repeater中radiobuttonlist如何绑定数据,请求完整代码块

html中:<asp:RepeaterID="Repeater1"runat="server"OnItemCommand="Repeater1_ItemCommand">... html中:
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<tr>
<td>
<%#Eval("M_Addate", "{0:yyyy-MM-dd}")%>
</td>
<td>
<p style="width: 180px;">
<%#Eval("M_Title")%></p>
</td>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
AutoPostBack="true">
</asp:RadioButtonList>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
CS中:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{

//RadioButtonList zj1 = (RadioButtonList)e.Item.FindControl("RadioButtonList1 ");
//HiddenField Mbit = (HiddenField)e.Item.FindControl("M_Bit");

//if (Mbit.Value.ToString() == "True")
//{
// zj1.Items[0].Selected = true;
//}

if (e.Item.ItemType == ListItemType.Item)
{
RadioButtonList rbl1 = (RadioButtonList)e.Item.FindControl("RadioButtonList1 ");
rbl1.DataSource = this.Repeater1.DataSource;
rbl1.DataTextField = "M_Bit";
rbl1.DataValueField = "M_ID";
rbl1.DataBind();
//if (Repeater1.Items[e.Item.ItemIndex].DataItem == "True ")
// rbl1.Items[0].Selected = true;

}
问题是在html中根本没有绑定出来。
展开
 我来答
平梦醉神风1I
推荐于2016-03-05 · TA获得超过1510个赞
知道小有建树答主
回答量:691
采纳率:0%
帮助的人:1032万
展开全部
事件错误,应该在ItemDataBound事件中处理,类似如下

<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<tr>
<td>
<%#Eval("M_Addate", "{0:yyyy-MM-dd}")%>
</td>
<td>
<p style="width: 180px;">
<%#Eval("M_Title")%></p>
</td>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
AutoPostBack="true">
</asp:RadioButtonList>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RadioButtonList rbl1 = (RadioButtonList)e.Item.FindControl("RadioButtonList1 ");
rbl1.DataSource = this.Repeater1.DataSource;
rbl1.DataTextField = "M_Bit";
rbl1.DataValueField = "M_ID";
rbl1.DataBind();
}
}
追问
rbl1.DataSource = this.Repeater1.DataSource;
在这一行是提示“未将对象引用设置到对象的实例。 ”;
追答
rbl1.DataSource = this.Repeater1.DataSource;
==
不能这样赋值,这里应该是
rbl1.DataSource = 你实际的数据源
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式