动态绑定datagrid中的dropdownlist后,dropdownlist没有值

来源:百度知道 编辑:UC知道 时间:2024/04/30 13:59:42
前台aspx:
<asp:datagrid id="dg" runat="server" Width="100%" AutoGenerateColumns="False">
<SelectedItemStyle BackColor="#FFC080"></SelectedItemStyle>
<HeaderStyle BackColor="#C0C000"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="xuehao" HeaderText="xuehao">
<HeaderStyle Width="30%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="xingming" HeaderText="xingming">
<HeaderStyle Width="30%"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="权限" HeaderStyle-Width="40%">
<ItemTemplate>
<asp:DropDownList ID="quanxian" Runat="

DropDownList quanxian = (DropDownList)e.Item.FindControl("quanxian");
这句里写的不对 不应该在ItemDataBound这个事件里写

我写了个例子 写的仓促 希望对你有帮助 主要是你那个 ItemBand里的你应该是少个判断

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList dl = (DropDownList)e.Row.FindControl("DropDownList1");
if (dl != null)//在这个地方判断一下
{
dl.DataSource = bind();
dl.DataTextField = "City";
dl.DataBind();
}
}