我有单选按钮,我需要在页面之间保持选择。我已经查找了所有解决方案,但我仍然对我应该做的事情感到困惑。 我将提供显示单选按钮功能的代码
.aspx page
<p>What Is Your Budget?
<asp:RadioButton ID="High_B" GroupName="Budget" runat="server" Text="High"
oncheckedchanged="High_B_CheckedChanged" ViewStateMode="Enabled"
AutoPostBack="True">
</asp:RadioButton>
<asp:RadioButton ID="Low_B" GroupName="Budget" runat="server" Text="Low"
oncheckedchanged="Low_B_CheckedChanged" AutoPostBack="True"
ViewStateMode="Enabled">
</asp:RadioButton>
</p>
<p>What is the level of excitement around FWC 2014?
<asp:RadioButton ID="High_E" GroupName="Radio" runat="server" Text="High"
oncheckedchanged="High__E_CheckedChanged" ViewStateMode="Enabled"
AutoPostBack="True">
</asp:RadioButton>
<asp:RadioButton ID="Low_E" GroupName="Radio" runat="server" Text="Low"
oncheckedchanged="Low_E_CheckedChanged" AutoPostBack="True"
ViewStateMode="Enabled">
</asp:RadioButton></p>
.aspx.cs页面
public void Chart()
{
if (High_E.Checked && High_B.Checked)
{
DataSet dSet = new DataSet();
dSet.ReadXml(Server.MapPath("~/ChartData/HighBud_Ex.xml"));
Chart1.DataSource = dSet.Tables[0];
Chart1.DataBind();
Session["name"] = "High";
setName();
}
if (High_E.Checked && Low_B.Checked)
{
DataSet dSet = new DataSet();
dSet.ReadXml(Server.MapPath("~/ChartData/LowBud_HighEx.xml"));
Chart1.DataSource = dSet.Tables[0];
Chart1.DataBind();
Session["name"] = "LowHigh";
setName();
}
if (Low_E.Checked && High_B.Checked)
{
DataSet dSet = new DataSet();
dSet.ReadXml(Server.MapPath("~/ChartData/HighBud_LowEx.xml"));
Chart1.DataSource = dSet.Tables[0];
Chart1.DataBind();
Session["name"] = "HighLow";
setName();
}
if (Low_E.Checked && Low_B.Checked)
{
DataSet dSet = new DataSet();
dSet.ReadXml(Server.MapPath("~/ChartData/LowBud_Ex.xml"));
Chart1.DataSource = dSet.Tables[0];
Chart1.DataBind();
Session["name"] = "Low";
setName();
}
答案 0 :(得分:2)
您应该在回发之间保留radioButtons的状态。也就是说,在oncheckedchanged
事件中,将您的单选按钮的状态保存在会话中,然后在回发后,将这些状态设置回来。
答案 1 :(得分:0)
我也有这个问题,我使用会话变量来存储单选按钮的状态,我做的是在回发时。我将单选按钮的状态存储在由逗号分隔的字符串中然后当我需要恢复状态时.i使用字符串拆分函数获取数组n中的值依赖于字符串我恢复了控件的状态