如何将一列GridView绑定到DropDownList?

时间:2013-03-06 09:01:38

标签: c# asp.net

我有一个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;
    }


}

2 个答案:

答案 0 :(得分:0)

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

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

此语句应嵌入for循环中。

答案 1 :(得分:0)

你可以在prerender活动中获得它。

protected void GridView1_PreRender(object sender, EventArgs e)
    {
        Label lblteachername = (Label)GridView1.Rows[i].FindControl("lblgridteachername");
         lblteachername.Text = teachername; 
    }