GridView嵌套RadioButtonList的绑定问题
--------------------编程问答-------------------- 我顶我顶我顶 --------------------编程问答-------------------- 参考下<asp:GridView ID="GridView1" runat="server">
<asp:TemplateField HeaderText="性别">
<ItemTemplate>
<asp:Label ID="lblSex" runat="server" Text='<%# Eval("易做图") %>'></asp:Label>
<asp:RadioButtonList ID="rblSex" runat="server">
</asp:RadioButtonList>
<asp:HiddenField ID="id" runat="server" Value='<%# Eval("id") %>' />
</asp:TemplateField>
</asp:GridView>
--------------------编程问答-------------------- 是一种方法,
protected void gvUser_RowDataBound(object sender, GridViewRowEventArgs e)
{
//判断是否是数据项
if (e.Row.RowType == DataControlRowType.DataRow)
{
//判断是否是编辑状态或交替行
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
RadioButtonList rblSex = (RadioButtonList)e.Row.FindControl("rblSex");//找到RadioButtonList
string id =( (HiddenField)e.Row.FindControl("rblSex")).Value;//找到关联键
rblSex.DataSource = xxxManager.GetXXById(id);//绑定RadioButtonList
rblSex.DataBind();
}
}
}
但是能否不在_RowDataBound里循环调用,
有没有方案支持在绑定GridView时直接将objectB.propertyA绑定给radiobuttonlist的?
--------------------编程问答-------------------- 找到了一个折中的方案:
--------------------编程问答-------------------- 目的是不再循环里调用数据库接口。
List<Option> Options = DataBinder.Eval(e.Row.DataItem, "Options") as List<Option>;
RadioButtonList rbl = e.Row.FindControl("rblOption") as RadioButtonList;
rbl.DataSource=Options;
rbl.DataBind();
--------------------编程问答-------------------- 参考下
<asp:GridView ID="GridView1" runat="server">
<asp:TemplateField HeaderText="性别">
<ItemTemplate>
<asp:Label ID="lblSex" runat="server" Text='<%# Eval("易做图") %>'></asp:Label>
<asp:RadioButtonList ID="rblSex" runat="server">
</asp:RadioButtonList>
<asp:HiddenField ID="id" runat="server" Value='<%# Eval("id") %>' />
</asp:TemplateField>
</asp:GridView>
protected void gvUser_RowDataBound(object sender, GridViewRowEventArgs e)
{
//判断是否是数据项
if (e.Row.RowType == DataControlRowType.DataRow)
{
//判断是否是编辑状态或交替行
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
RadioButtonList rblSex = (RadioButtonList)e.Row.FindControl("rblSex");//找到RadioButtonList
string id =( (HiddenField)e.Row.FindControl("rblSex")).Value;//找到关联键
rblSex.DataSource = xxxManager.GetXXById(id);//绑定RadioButtonList
rblSex.DataBind();
}
}
}
补充:.NET技术 , ASP.NET