0

我有一个 GridView,我想将第一个 Column(teachername) 与我在 GridView 之外的 DropDownList 绑定。我怎样才能让它工作?

 protected void Button2_Click(object sender, EventArgs e)
{
     string q = "select * from teacher where teachername='" + drpteachername.SelectedItem.ToString() + "'  and ('2013-03-01' between date and todate) and '2013-03-31' between date and todate";
    dt = dbo.Getdt(q);
    GridView1.DataSource = dt;
    GridView1.DataBind();
    string teachername=drpteachername.SelectedItem.ToString();


    for (int i = 0; i < dt.Rows.Count ;i++ )
    {
        Label lblteachername = (Label)GridView1.Rows[i].Cells[0].FindControl("lblgridteachername");

                  this.GridView1.Rows[i].Cells[0].Value = teachername;
    }


}
4

2 回答 2

0

尝试使用this.GridView1.Rows[i].Cells[0].Value = teachername;

如果您感到任何困惑,请不要犹豫写。

该语句应嵌入 for 循环中。

于 2013-03-06T09:11:05.870 回答
0

您可以在预渲染事件中获取它。

protected void GridView1_PreRender(object sender, EventArgs e)
    {
        Label lblteachername = (Label)GridView1.Rows[i].FindControl("lblgridteachername");
         lblteachername.Text = teachername; 
    }
于 2013-03-06T09:25:43.287 回答