gridview下拉框

 protected void GVrentDetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        ListItem NewItem;
        string sql;
        DataTable dt;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList drop01 = (DropDownList)e.Row.FindControl("ddlRentType");
            sql = "select * from dict where fieldMark='rentType'";
            dt = commonCls.GetDataTable(sql);
            drop01.DataSource = dt;
            drop01.DataTextField = "fieldValue";
            drop01.DataValueField = "fieldValue";
            drop01.DataBind();
            NewItem = new ListItem();
            NewItem.Value = "qxz";
            NewItem.Text = "请选择";
            drop01.Items.Insert(0, NewItem);
            drop01.SelectedValue = DataBinder.Eval(e.Row.DataItem, "rentType").ToString();

            DropDownList drop02 = (DropDownList)e.Row.FindControl("ddlInExpType");
            sql = "select * from dict where fieldMark='InExpType'";
            dt = commonCls.GetDataTable(sql);
            drop02.DataSource = dt;
            drop02.DataTextField = "fieldValue";
            drop02.DataValueField = "fieldValue";
            drop02.DataBind();
            NewItem = new ListItem();
            NewItem.Value = "qxz";
            NewItem.Text = "请选择";
            drop02.Items.Insert(0, NewItem);
            drop02.SelectedValue = DataBinder.Eval(e.Row.DataItem, "InExpType").ToString();
        }
    }
View Code

在RowDataBound事件中绑定下拉框,设置值drop01.SelectedValue = DataBinder.Eval(e.Row.DataItem, "rentType").ToString();

转载于:https://www.cnblogs.com/zhaolijing910/archive/2013/05/29/3106387.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值