0

我在 asp.net 的 aspx 页面中有一个 gridview3。我已经用数据源绑定了 gridview

Gridview 有行按钮。在行按钮中单击,即使我已经编写了 cs 代码来制作一页

标签的可见真实并将另一个gridview2与datasour绑定..

我的网格视图事件正在运行并在运行时读取代码,但我的页面标签

可见性没有发生,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();

        }



    }
}  
4

1 回答 1

1

您需要在所选行内找到标签和网格视图。您的代码应如下所示:

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();

        }

    }
}  
于 2013-11-09T23:07:09.967 回答