c#
  • asp.net
  • 2013-03-06 103 views 0 likes 
    0

    我有一个GridView,我想绑定第一列(教师名)与DropDownList,我有GridView外。我怎样才能使它工作?如何将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; 
        } 
    
    
    } 
    
    +0

    *你有什么*问题? – 2013-03-06 09:07:51

    +0

    @huMptyduMpty没有任何反应,我点击按钮。上面的代码既没有给我任何结果,也没有任何错误。 – Arbaaz 2013-03-06 09:11:48

    +0

    我收到错误 {“索引超出范围,必须是非负值,小于集合的大小\ r \ n参数名称:index”} – Arbaaz 2013-03-06 10:48:04

    回答

    0

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

    不要犹豫,如果你觉得任何迷惑写。

    这条语句应该嵌入for循环。

    +0

    system.web.ui.webcontrols.tablecell'not包含“价值”的定义 – Arbaaz 2013-03-06 09:16:06

    +0

    它对我来说工作得很好。您正在使用哪种版本的.NET? – 2013-03-06 09:21:37

    +0

    我正在使用.NET框架4.0。我编辑了我的代码,看看我是否正确。 – Arbaaz 2013-03-06 09:46:09

    0

    你可以在prerender事件中得到它。

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