前台用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 = "";
                }

解决方案 »

  1.   

    你写的就是对的!
    不过把 tempcheck 定义成public
      

  2.   

    CS里定义:
    protect string tempcheck;在前台.aspx就能引用了  <% =tempcheck %>
      

  3.   

    public string                     tempcheck ;
      

  4.   

    用这个   <asp:RadioButton  Checked="true" runat="server" />吧
    Checked='<%=tempcheck%>'
    后台判断,返回真假
    前台接!
    <input type="radio" >
    这个东西不行!
      

  5.   

    <% =tempcheck %>绑定的串,放前台当属性?个人感觉肯定不行!
    还是用asp:RadioButton这样的服务器控件方便些!
      

  6.   

    <input name="smstype" type="radio" value="yes" <%=tempcheck%> >开启 
    <input type="radio" name="smstype" value="no" <%=tempcheck%> > 关闭 
    改成两个服务器控件,然后后台定义两个公共变量,tempcheck1和tempcheck2,分开绑不就行了!
      

  7.   

    楼上的 一星 大哥,请问能详细地说一下,如果我改成: <asp:RadioButton  Checked="true" runat="server" /> 应该如何写??具体的? 物别是前台如何写??
      

  8.   

    前台<ASP:RadioButton Id="Radio1" Text="RadioButton1" GroupName="Group1" 
    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"; 

      

  9.   


    前台
    <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"/> 
      

  10.   


    if (dr["smstype"].ToString().TrimEnd() == "yes") 

    Radio1.Checked = "true"; 
    Radio2.Checked ="false"; 
    } else 

    Radio2.Checked = "true"; 
    Radio1.Checked ="false" ;
      

  11.   

    如果你想再得到前台的值:
    在后台还可以再做判断
    if(Radio1.checked=="true")
    {
    string mystate="开启";
    }
    else
    {
    string mystate="关闭";
    }
      

  12.   

    一着急弄差了,歉意!
    Radio1.Checked ="true"; 
    应该是Radio1.Checked =true;
      

  13.   

    <input name="smstype" type="radio" check='<%=tempcheck%>' >开启 protected string tempcheck {
    get { 
    //...
    if (dr["smstype"].ToString().TrimEnd() == "yes") 
                    { 
                        tempcheck = "checked"; 
                    }                 else 
                    { 
                        tempcheck = "unchecked";                 } 
    // ...
      

  14.   

    ssoorryy, ->checked=' <%=tempcheck%>' 
      

  15.   

    if(Radio1.checked)
    {
    string mystate="yes";
    }
    else
    {
    string mystate="no";
    }