RadioButtonList 无法触发回传事件

QASDD 2016-09-23 11:19:22

<asp:ScriptManager ID="ScriptManagerLable" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanelLable" runat="server">
<ContentTemplate>
<table>
<tr><td>主标签:</td><td><asp:RadioButtonList ID="RadioButtonList1Lable" CssClass="SelectButton" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1Lable_SelectedIndexChanged">
<asp:ListItem Selected="True">心情</asp:ListItem>
<asp:ListItem>随笔</asp:ListItem>
<asp:ListItem>相册</asp:ListItem>
<asp:ListItem>笔记</asp:ListItem>
<asp:ListItem>分享</asp:ListItem>
</asp:RadioButtonList></td>
<td>主标签不能被编辑</td>
</tr>
<tr><td>次级标签:</td>
<td>
<asp:RadioButtonList ID="RadioButtonList2Lable" runat="server" CssClass="SelectButton" RepeatDirection="Horizontal" RepeatLayout="Flow" DataTextField="className" DataValueField="className" OnSelectedIndexChanged="RadioButtonList2Lable_SelectedIndexChanged" AutoPostBack="true"></asp:RadioButtonList>
<asp:CheckBoxList ID="CheckBoxList2Label" runat="server" CssClass="SelectButton dn" RepeatDirection="Horizontal" RepeatLayout="Flow" DataTextField="className" DataValueField="className">
</asp:CheckBoxList>
<em><asp:Literal ID="Lable2tips" runat="server"></asp:Literal></em>
</td><td>
<a href="javascript:Ledit()" id="Ledit">编辑</a><br />
<div class="dn">
<a href="javascript:show()">添加</a><br />
<a href="#">删除选中</a><br />
<asp:CheckBox ID="DelAllCheckBox" runat="server" CssClass="cb" />包括次级<br />
</div>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>



主标签可以正常选择,次标签首个选中是默认选中


当选择www,eee,rrr,ttt标签的时候会自动刷新回默认标签,后台事件没有执行


只有选择最后一个标签时,就会执行一次后台SelectIndexChange事件,但是再点击前面的www,eee,rrr,ttt标签时又不执行后台数据了,并且选中的项又跳回了最后一个标签。

后台代码


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ radioOnLoad(); }
}

public void radioOnLoad ()
{
switch (RadioButtonList1Lable.SelectedValue)
{
case "心情":
radioDataBind("心情");
break;
case "随笔":
radioDataBind("随笔");
break;
case "相册":
radioDataBind("相册");
break;
case "笔记":
radioDataBind("笔记");
break;
case "分享":
radioDataBind("分享");
break;
default:
radioDataBind(null);
break;
}
KeyCheckBox(RadioButtonList2Lable.SelectedValue);
}

public void radioDataBind(string asc)
{
Lable2tips.Text = null;
if (asc == null)
{
Lable2tips.Text = "未选择事件。"; return;
}
var cN = from c in db.classTable where c.ascription == asc select c;
//单选组件
RadioButtonList2Lable.DataSource = cN;
RadioButtonList2Lable.DataBind();
if (RadioButtonList2Lable.Items.Count == 0)
{
Lable2tips.Text = "未添加绑定。<a href='javascript:show()'>添加</a>";
}
else
{
RadioButtonList2Lable.Items[0].Selected = true;
}

//触发编辑 复选组件
CheckBoxList2Label.DataSource = cN;
CheckBoxList2Label.DataBind();
}

protected void RadioButtonList1Lable_SelectedIndexChanged(object sender, EventArgs e)
{
radioOnLoad();
}
protected void RadioButtonList2Lable_SelectedIndexChanged(object sender, EventArgs e)
{
KeyCheckBox(RadioButtonList2Lable.SelectedValue);
}
...全文
253 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanglong_longlong 2016-09-23
  • 打赏
  • 举报
回复
AutoPostBack设置true
摇撼大地 2016-09-23
  • 打赏
  • 举报
回复
这里我之前做的时候。 需要注意两点。一个是IsPostBack。这个能保存控件的状态。 一个是标签的AutoPostBack。然后一个一个调试就行了。

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧