我在asp.net中的aspx页面中有一个gridview3。我已将gridview与数据源绑定
Gridview有行按钮。在行按钮中单击甚至我已经编写了cs代码来制作一个页面
标签显示为true并将另一个gridview2与datasour绑定..
我的网格视图事件正在运行并在运行时读取代码,但我的页面标签是
visiblity没有发生,gridview2没有通过数据源显示数据
显示数据..请帮助..
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = GridView3.Rows[index];
DateTime frmdt = this.DateRangePicker2.FromDate;
DateTime Tomdt = this.DateRangePicker2.ToDate;
if (e.CommandName == "btnPrvViewp")
{
if (selectedRow.Cells[1].Text == "Indirect Process" && selectedRow.Cells[2].Text == "SAP")
{
this.lbel1.Text = "Productivity Detaisl for the period " + frmdt + " To " + Tomdt;
this.lbel1.Visible = true;
SqlConnection conn = new SqlConnection(str2);
SqlCommand com = new SqlCommand("ViewProductivity", conn);
com.Parameters.Add("@fromDate", SqlDbType.DateTime ).Value = frmdt;
com.Parameters.Add("@ToDate", SqlDbType.DateTime).Value = Tomdt;
conn.Open();
com.CommandType = CommandType.StoredProcedure;
SqlDataReader readerp = com.ExecuteReader();
GridView2.DataSource = readerp;
GridView2.DataBind();
readerp.Close();
}
}
}
答案 0 :(得分:1)
您需要在所选行中找到标签和gridview。您的代码应如下所示:
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = GridView3.Rows[index];
DateTime frmdt = this.DateRangePicker2.FromDate;
DateTime Tomdt = this.DateRangePicker2.ToDate;
if (e.CommandName == "btnPrvViewp")
{
if (selectedRow.Cells[1].Text == "Indirect Process" && selectedRow.Cells[2].Text == "SAP")
{
Label lbel1 = selectedRow.FindControl("lbel1") as Label;
GridView GridView2 = selectedRow.FindControl("GridView2") as GridView;
lbel1.Text = "Productivity Detaisl for the period " + frmdt + " To " + Tomdt;
lbel1.Visible = true;
SqlConnection conn = new SqlConnection(str2);
SqlCommand com = new SqlCommand("ViewProductivity", conn);
com.Parameters.Add("@fromDate", SqlDbType.DateTime).Value = frmdt;
com.Parameters.Add("@ToDate", SqlDbType.DateTime).Value = Tomdt;
conn.Open();
com.CommandType = CommandType.StoredProcedure;
SqlDataReader readerp = com.ExecuteReader();
GridView2.DataSource = readerp;
GridView2.DataBind();
readerp.Close();
}
}
}