单选按钮故障... [英] trouble in radio button...

查看:80
本文介绍了单选按钮故障...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了4个单选按钮..

 <   div     class   =  reg-child >  
< div class = reg-child-text > 正文类型:< / div >
< div class = red-chil d-input id = change_basic_bodytype >
< ; 输入 type < span class =code-keyword> = radio value = 超薄 runat < span class =code-keyword> = server 名称 = 正文类型 id = rado_slim / > < label = rado_slim > Slim < / label >
< 输入 type = radio value = 平均值 runat = server name < span class =code-keyword> = 正文类型 id = rado_average / > < label for = rado_average > 平均< /标签 >
< 输入 类型 = radio = 运动 runat = server name = 正文类型 id = rado_athletic < span class =code-keyword> / > < 标签 = rado_athletic > Athletic < / label >
< 输入 type = radio = runat = server 名称 = 正文类型 id = rado_heavy / > < label < span class =code-attribute> for = rado_heavy > < / label >
< / div >
< / div >





当我选择上面的值并单击提交按钮时,特定值传递到其他文本框中...这个条件成功运行..当我单击提交按钮而不选择radiobutton..a未定义值保存在数据库中旧数据自动删除和该位置未定义..可以解决此问题

解决方案

试试这个代码...



这个aspx代码

 <   asp:radiobuttonlist     id   =  rbtn_option    runat   =  server    xmlns:asp   = #unknown >  
RepeatDirection = 水平 >
< asp:listitem > item1 < / asp:listitem >
< asp:listitem > item2 < / asp:listitem >
< asp:listitem > item3 < / asp:listitem >
< asp:listitem < span class =code-keyword>> item4 < / asp:listitem >
< / asp:radiobuttonlist >

< asp:textbox id = txt_val runat = server xmlns:asp = #unknown > < / asp:textbox >
< span class =code-keyword>< asp:button id = btn_submit runat = server onclick = < span class =code-keyword> btn_submit_Click xmlns:asp = #unknown >
Text =提交/>
< / asp:button >





这个后面的代码

  protected   void  btn_submit_Click( object  sender,EventArgs e)
{
if (rbtn_option.SelectedIndex < 0
return ;

txt_val.Text = rbtn_option.SelectedValue;
}







我希望它会对你有所帮助。,br />


谢谢你,上帝保佑..


提交时,检查是否选择了Radio Buttons。如果选中,则读取值并保存到数据库,否则不保存。



我确定,您没有检查这个并直接保存该值。 / blockquote>

嗨rajeeshmenoth,



试试这个



对于演示:小鸡在这里



HTML

 <   div     class   =  reg-child >  
< div class = reg-child-text > 正文类型:
< 输入 类型 = text runat = server name = 正文类型 id = textbox / > < / div >
< div class = red-child-input id = change_basic_bodytype >
< 输入 type = radio value = Slim runat = server name = Body_type id = rado_slim / > < label = rado_slim > Slim < / label >
< 输入 type = radio = 平均 runat = server name = Body_type id = rado_average / < span class =code-keyword>>
< la bel = rado_average > 平均< / label >
< span class =code-keyword><
input type = radio value = Athletic runat = server 名称 = Body_type id = rado_athletic / > < label for = rado_athletic < span class =code-attribute> > 运动< / label >
< input 类型 = radio value = < span class =code-keyword> Heavy runat = server 名称 = Body_type id = rado_heavy / > < label for = rado_heavy > < /标签 >

< / div >
< 输入 type = 按钮 id = btnStatus value = Radio B utton状态 / >
< input 类型 = 按钮 id = btnReset value = 无线电重置 / >
< / div >





JQ

 

I have created 4 radio button..

<div class="reg-child">
  <div class="reg-child-text">Body type :</div>
    <div class="red-child-input" id="change_basic_bodytype">
     <input type="radio"  value="Slim"  runat="server" name="Body type" id="rado_slim" /><label for="rado_slim" >Slim</label>
     <input type="radio"  value="Average" runat="server" name="Body type" id="rado_average" /><label for="rado_average" >Average</label>
      <input type="radio"  value="Athletic" runat="server" name="Body type" id="rado_athletic" /><label for="rado_athletic" >Athletic</label>
         <input type="radio"  value="Heavy" runat="server" name="Body type" id="rado_heavy" /><label for="rado_heavy" >Heavy</label>
    </div>
 </div>



when i select the above value and click submit button,the particular value passed into other textbox..this condition is successfully working..when i click the submit button without selecting a radiobutton..a "undefined" value saved in database the old data automatically deleted and that position "undefined" ..can u solve this problem

解决方案

Try this code...

this the aspx code

    <asp:radiobuttonlist id="rbtn_option" runat="server" xmlns:asp="#unknown">
        RepeatDirection="Horizontal">
        <asp:listitem>item1</asp:listitem>
        <asp:listitem>item2</asp:listitem>
        <asp:listitem>item3</asp:listitem>
        <asp:listitem>item4</asp:listitem>
    </asp:radiobuttonlist>

    <asp:textbox id="txt_val" runat="server" xmlns:asp="#unknown"></asp:textbox>
    <asp:button id="btn_submit" runat="server" onclick="btn_submit_Click" xmlns:asp="#unknown">
        Text="Submit" />
</asp:button>



this the behind code

protected void btn_submit_Click(object sender, EventArgs e)
{
    if (rbtn_option.SelectedIndex < 0)
        return;

    txt_val.Text = rbtn_option.SelectedValue;
}




I hope it will help you.,

thank you and God bless..


While submitting, check if Radio Buttons are selected or not. If selected, then read the value and save to database, else don't save.

I am sure, you are not checking this and directly saving the value.


Hi rajeeshmenoth,

Try this

For DEMO: Chick Here

HTML

<div class="reg-child">
  <div class="reg-child-text">Body type :
    <input type="text"  runat="server" name="Body type" id="textbox" /></div>
    <div class="red-child-input" id="change_basic_bodytype">
     <input type="radio"  value="Slim"  runat="server" name="Body_type" id="rado_slim" /><label for="rado_slim" >Slim</label>
     <input type="radio"  value="Average" runat="server" name="Body_type" id="rado_average" /><label for="rado_average" >Average</label>
      <input type="radio"  value="Athletic" runat="server" name="Body_type" id="rado_athletic" /><label for="rado_athletic" >Athletic</label>
         <input type="radio"  value="Heavy" runat="server" name="Body_type" id="rado_heavy" /><label for="rado_heavy" >Heavy</label>
        
    </div>
    <input type="button" id="btnStatus" value="Radio Button status" />
    <input type="button" id="btnReset" value="Radio Reset" />
 </div>



JQ


这篇关于单选按钮故障...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆