我希望使用asp.net,C#4.0& amp;中的矩阵概念在gridview中显示数据。 oracle 11g
能够在页面加载事件
时在gridview中动态绑定数据我的要求是
Activity1 activity2 activity3 ... activity 10
Monday & date
tuesday & date
wednesday & date
。 。 。
Sunday & date
我试过的代码
protected void GetActivity()
{
string query2 = "Select ACTIVITY1,ACTIVITY2,ACTIVITY3,ACTIVITY4,ACTIVITY5,ACTIVITY6,TOTALDURTN from DAILY_ACTIVITIES order by ACTIVITYNO asc";
using (OracleConnection CON = new OracleConnection(strConnection))
{
using (OracleCommand command2 = new OracleCommand(query2, CON))
{
CON.Open();
DataTable DTBLE2 = new DataTable();
OracleDataAdapter OracleDA2 = new OracleDataAdapter(command2);
OracleDA2.Fill(DTBLE2);
ViewState["dt"] = DTBLE2;
this.BindGrid();
}
}
}
protected void BindGrid()
{
DisplayGridView.DataSource = ViewState["dt"] as DataTable;
DisplayGridView.DataBind();
}
protected void OnRowEditing(object sender, GridViewEditEventArgs e)
{
DisplayGridView.EditIndex = e.NewEditIndex;
this.BindGrid();
}
protected void OnCancel(object sender, EventArgs e)
{
DisplayGridView.EditIndex = -1;
this.BindGrid();
}
protected void OnUpdate(object sender, EventArgs e)
{
GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow;
string ACTIVITY1 = (row.Cells[0].Controls[0] as TextBox).Text;
string ACTIVITY2 = (row.Cells[1].Controls[0] as TextBox).Text;
string ACTIVITY3 = (row.Cells[2].Controls[0] as TextBox).Text;
string ACTIVITY4 = (row.Cells[3].Controls[0] as TextBox).Text;
string ACTIVITY5 = (row.Cells[4].Controls[0] as TextBox).Text;
string ACTIVITY6 = (row.Cells[5].Controls[0] as TextBox).Text;
string TOTALDURTN = (row.Cells[6].Controls[0] as TextBox).Text;
DataTable dt = ViewState["dt"] as DataTable;
dt.Rows[row.RowIndex]["ACTIVITY1"] = ACTIVITY1;
dt.Rows[row.RowIndex]["ACTIVITY2"] = ACTIVITY2;
dt.Rows[row.RowIndex]["ACTIVITY3"] = ACTIVITY3;
dt.Rows[row.RowIndex]["ACTIVITY4"] = ACTIVITY4;
dt.Rows[row.RowIndex]["ACTIVITY5"] = ACTIVITY5;
dt.Rows[row.RowIndex]["ACTIVITY6"] = ACTIVITY6;
dt.Rows[row.RowIndex]["TOTALDURTN"] = TOTALDURTN;
ViewState["dt"] = dt;
DisplayGridView.EditIndex = -1;
this.BindGrid();
}
protected void DisplayGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 0)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = DateTime.Now.ToShortDateString();
//e.Row.Cells[0].Text = DateTime.Now.ToShortDateString();
}
}
}
我可以用gridview这样做吗?