GridView里绑定DropdownList

 

前台截取部分
1 <asp:TemplateField HeaderText="是否发放" SortExpression="YesNo">

2                 <ItemTemplate>

3                      <asp:DropDownList ID="ddl_YesNo" runat="server"  DataSource='<%# ddlbind() %>' DataTextField="YesNo"  DataValueField="YesNo">

4                      </asp:DropDownList>

5                  </ItemTemplate>

6                <EditItemTemplate>

7                      <asp:TextBox ID="TextBox30" runat="server" Text='<%# Bind("YesNo") %>'></asp:TextBox>

8                 </EditItemTemplate>

 

 

 

 

 

 

 1         //绑定数据得到这个表的所有项,

 2         //两个字段(1.id, 2.YesNo)       

 3         public DataSet ddlbind()

 4         {

 5             DataSet bbl = new BLL.J_Pay_YesNo().GetAllList();

 6             return bbl;

 7         }

 8 

 9         protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)

10         {

11             if (e.Row.RowType == DataControlRowType.DataRow)

12             {

13                 DropDownList ddlClass = e.Row.FindControl("ddl_YesNo") as DropDownList;

14                 DataSet ds = bll.GetAllList();

15                 ddlClass.DataSource = ds;

16                 ddlClass.SelectedValue = DataBinder.Eval(e.Row.DataItem, "YesNo").ToString();

17             }

18         }

 

 

 

你可能感兴趣的:(GridView)