首页 新闻 会员 周边

gridview绑定dropdownlist问题

0
[已关闭问题]

gridview绑定dropdownlist,给dropdownlist赋值,网上都是这样的代码

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList goodsType
= (DropDownList)e.Row.FindControl("DropDownList1");
if (goodsType != null)
{
con
= new SqlConnection(ConfigurationManager.ConnectionStrings["TestProviderConnectionString"].ConnectionString);
DataSet ds
= new DataSet();
SqlDataAdapter da
= new SqlDataAdapter("select * from goodsType",con);
da.Fill(ds,
"gt");
goodsType.DataSource
= ds.Tables["gt"];
goodsType.DataTextField
= "goodsType";
goodsType.DataValueField
= "goodsId";
goodsType.DataBind();
}
}
}

但是每列绑定的时候都读取一遍数据库,我感觉很慢,有没有好的办法啊

<HOU>的主页 <HOU> | 菜鸟二级 | 园豆:205
提问于:2009-03-02 12:43
< >
分享
其他回答(3)
0

你把数据一次取出,再绑定不就行啦

sendy | 园豆:205 (菜鸟二级) | 2009-03-02 13:01
0

如果下拉框相同 而且有很多

可以考虑在客户端绑定

如果不同 可以考虑用cache

小眼睛老鼠 | 园豆:2731 (老鸟四级) | 2009-03-02 13:39
0

用一个下拉控件,初始化时取出数据并隐藏,在点击Grid的那一单元格时让其在GRID那个单元格里显示,选中后将值写入GRID的该单元中就行了。

| 园豆:770 (小虾三级) | 2009-03-02 17:10
0

你是想在GridView编辑时用Dropdownlist吧,可以看一下我的代码:

string select =((Label) GridView1.Rows[e.NewEditIndex].Cells[1].Controls[1]).Text;
        GridView1.EditIndex = e.NewEditIndex;
        Bind();

        //给品牌添加列表
        HtmlSelect brand=(HtmlSelect)GridView1.Rows[e.NewEditIndex].FindControl("selBrand");
        brand.DataSource = db.GetDataSet("select * from tb_Brand");
        brand.DataTextField = "bname";
        brand.DataBind();
        brand.Value = select;

先在未绑定之前取出之前的值,好让;dropdownlist选中该项,

我用的是<input type="select" runat="server"/>用;dropdownlist是一样的

天好高 | 园豆:230 (菜鸟二级) | 2009-03-06 11:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册