前台用html做了一个单选按钮组,按钮开始的选中状态由 后台.cs一个变量控制tempcheck,tempcheck是根据数据表中对应记录的值来确定的。如何做到:程序运行时从数据表中读取当前记录的 smstype属性,如果对应的值是smstype="yes"时,选中“开启”,smstype="no"时,选中“关闭”关键是前台如果实现??谢谢
前台.aspx文件<input name="smstype" type="radio" value="yes" <%=tempcheck%> >开启
<input type="radio" name="smstype" value="no" <%=tempcheck%> > 关闭
后台.cs文件if (dr["smstype"].ToString().TrimEnd() == "yes")
{
tempcheck = "checked";
} else
{
tempcheck = "";
}
前台.aspx文件<input name="smstype" type="radio" value="yes" <%=tempcheck%> >开启
<input type="radio" name="smstype" value="no" <%=tempcheck%> > 关闭
后台.cs文件if (dr["smstype"].ToString().TrimEnd() == "yes")
{
tempcheck = "checked";
} else
{
tempcheck = "";
}
不过把 tempcheck 定义成public
protect string tempcheck;在前台.aspx就能引用了 <% =tempcheck %>
Checked='<%=tempcheck%>'
后台判断,返回真假
前台接!
<input type="radio" >
这个东西不行!
还是用asp:RadioButton这样的服务器控件方便些!
<input type="radio" name="smstype" value="no" <%=tempcheck%> > 关闭
改成两个服务器控件,然后后台定义两个公共变量,tempcheck1和tempcheck2,分开绑不就行了!
AutoPostBack="True"
OnCheckedChanged="Check_Clicked"
Runat="Server" checked='<%=tempcheck1 %>'/><Br>
<ASP:RadioButton Id="Radio2" Text="RadioButton2" GroupName="Group1"
AutoPostBack="True"
OnCheckedChanged="Check_Clicked"
Runat="Server" checked='<%=tempcheck2 %>'/> 后台if (dr["smstype"].ToString().TrimEnd() == "yes")
{
tempcheck1 = "true";
tempcheck2 ="false" ;
}
else
{
tempcheck1 ="false" ;
tempcheck2 = "true";
}
前台
<ASP:RadioButton Id="Radio1" Text="开启" GroupName="Group1"
AutoPostBack="True"
OnCheckedChanged="Check_Clicked"
Runat="Server"><Br>
<ASP:RadioButton Id="Radio2" Text="关闭" GroupName="Group1"
AutoPostBack="True"
OnCheckedChanged="Check_Clicked"
Runat="Server"/>
if (dr["smstype"].ToString().TrimEnd() == "yes")
{
Radio1.Checked = "true";
Radio2.Checked ="false";
} else
{
Radio2.Checked = "true";
Radio1.Checked ="false" ;
}
在后台还可以再做判断
if(Radio1.checked=="true")
{
string mystate="开启";
}
else
{
string mystate="关闭";
}
Radio1.Checked ="true";
应该是Radio1.Checked =true;
get {
//...
if (dr["smstype"].ToString().TrimEnd() == "yes")
{
tempcheck = "checked";
} else
{
tempcheck = "unchecked"; }
// ...
{
string mystate="yes";
}
else
{
string mystate="no";
}