Retriveing the value for radio btn

Posted by Gokularts2006 under C# on 4/19/2012 | Points: 10 | Views : 723 | Status : [Member] | Replies : 4
Hi

I have a two radiobuttons. I can insert the value in database ,save like as bit value(true or fasle), Again i need to select the value from db.

I need the coding for select vlue of radio btn.

Thanks

Gokulakrishnan


Responses

Posted by: Sabarimahesh on: 4/19/2012 [Member] Bronze | Points: 25

Up
0
Down
Asp

<asp:RadioButton ID="rb_Yes" runat="server" GroupName="GpName" Text="Yes" OnCheckedChanged="rb_Yes_Click" AutoPostBack="true" />

<asp:RadioButton ID="rb_No" runat="server" GroupName="GpName" Text="No" OnCheckedChanged="rb_No_Click" AutoPostBack="true"/
>


C#

protected void rb_Yes_Click(object sender, EventArgs e)

{
RadioButton rb_Yes = (RadioButton)sender;
GridViewRow grid_row = (GridViewRow)rb_Yes.NamingContainer;
if(((RadioButton)grid_row.FindControl("rb_Yes")).Checked==true)
{
//Action that you want to implement
}
}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gokularts2006, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/19/2012 [Member] Bronze | Points: 25

Up
0
Down
Using Jquery


<script type="text/javascript" language="javascript">

function scoreQuiz(form) {

var count = 0;

if ($('#<%=rbYesOne.ClientID%> radio:selected').val() == "1") {
alert("YES");
}

if ($('#<%=rbNoOne.ClientID%> radio:selected').val() == "0") {
alert("NO");
}

else {
alert("FU......");
}
</script>

<div class="row">
<asp:RadioButton ID="rbYesOne" value="1" runat="server" GroupName="Question1" />
<asp:RadioButton ID="rbNoOne" value="0" runat="server" GroupName="Question1" />
<!-- and twelve more... -->
</div>


<script type="text/javascript" language="javascript">
var rbYesOne = document.getElementById('<%=rbYesOne.ClientID%>');
var rbNoOne = document.getElementById('<%=rbNoOne.ClientID%>');
/* and twelve more...*/
</script>


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gokularts2006, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/19/2012 [Member] Bronze | Points: 25

Up
0
Down
function CheckRadioListSelectedItem(name) {


var radioButtons = document.getElementsByName(name);
var Cells = radioButtons[0].cells.length;

for (var x = 0; x < Cells; x++) {
if (document.getElementsByName(name + '_' + x)[0].checked) {
return x;
}
}

return -1;
}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gokularts2006, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gokularts2006 on: 4/19/2012 [Member] Starter | Points: 25

Up
0
Down
Hi
i need to retrive by c# coding only and also i did not use grdiview.Just i want to select the value and want to display the aspx page.I try the coding below mention .
protected void btnSerch_Click(object sender, EventArgs e)
{

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SelectItems";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.Parameters.Add("@Id", SqlDbType.Int).Value = txtId.Text;

SqlDataReader dr = cmd.ExecuteReader();
dr.Read();


txtName.Text = dr["UserName"].ToString();

if (dr["Male"].ToString() == "true")
{
rbMale.Checked = true;
}
else
{
rbFemale.Checked = false;
}




//cmd.ExecuteNonQuery();
con.Close();
}
}

But in this code if condition not work properly kindly modify it

Thanks

Gokulakrishnan

Gokularts2006, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response