repeater中嵌套绑定RedioButtonList值问题?请求完整的代码块。谢谢。。。
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中根本没有绑定出来。 展开
<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中根本没有绑定出来。 展开
1个回答
展开全部
事件错误,应该在ItemDataBound事件中处理,并且多加一个判断
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//...
}
}
详细代码贴在http://zhidao.baidu.com/question/310619802.html#here
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//...
}
}
详细代码贴在http://zhidao.baidu.com/question/310619802.html#here
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询