[已解决问题] gridView 中的数据绑定问题?
提问时间: 2008-04-24 11:20
悬赏分:5 浏览:497 次

 请看下面,下面是怎么会事?

在下面的中DropDownList1上绑定了数据。

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType ==DataControlRowType.DataRow)
        {
            DataSet Ds = new DataSet();
            DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
            string Name = "GetBooks";//存储过程名字
            int strWhere = 0;//表示查询条件为空

            //访问类库的Sql静态方法
            Ds = DB.GetList(Name, strWhere);
            if (Ds.Tables[0].Rows.Count != 0)
            {
                ///绑定数据
                ddl.DataSource = Ds;
                ddl.DataTextField = "AuthorName";
                ddl.DataValueField = "AuthorName";
            }

        //    Button btnDel = (Button)e.Row.FindControl("btndel");
        //    btnDel.Attributes.Add("onclick", "return confirm('真的要删除吗?')");
        }
    }

在下面的中DropDownList1上绑定不了数据。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ////DataSet Ds = new DataSet();
            ////DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
            ////string Name = "GetBooks";//存储过程名字
  &

提问者:HamunNet - 初学一级
最佳答案
GridView1和DropDownList1的DataBind()执行先后的问题造成了上述原因。 你要在GridView1执行DataBind()之前给DropDownList1数据源。RowDataBound是GridView1的DataBind()的伴随事件。所以不能绑定。
2008/4/24 11:50:50 回答者:kic


提问者对于答案的评价:谢谢你的提示啊!
评论
5个月前   HamunNet :
明白,谢谢啊!
5个月前   HamunNet :
再谢谢的你的提示!
   您需要登录以后才能回答!
 

我要提问

我的问题


快到期问题

> 问题排行榜

相关内容

相关链接