count how many times a radio button is selected [Resolved]

Posted by Saanjhi under C# on 9/13/2013 | Points: 10 | Views : 3473 | Status : [Member] | Replies : 4
count how many times a radio button is selected and ans is shown in textbox.




Responses

Posted by: Bandi on: 9/13/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
RadioButton.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadioButton.aspx.cs" Inherits="RadioButtonListEx.RadioButton" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<div>

<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">

<asp:ListItem Selected="True">Hello!</asp:ListItem>

<asp:ListItem>First Time!</asp:ListItem>

<asp:ListItem>second Time!</asp:ListItem>

<asp:ListItem>Third Time!</asp:ListItem>

</asp:RadioButtonList></div>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox runat="server" id="txtCount"/>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTrigger ControlID="RadioButtonList1" EventName="SelectedIndexChanged" />

</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>


RadioButton.aspx.cs
using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RadioButtonListEx
{
public partial class RadioButton : System.Web.UI.Page
{
static int count = 0;
protected void Page_Load(object sender, EventArgs e)
{

}

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
count = count + 1;
Label1.Text = RadioButtonList1.SelectedValue;
txtCount.Text = count.ToString();
}

}
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Satyapriyanayak on: 9/13/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Radio_button_count
{
public partial class Form1 : Form
{
int radiobtn_count = 0;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
radiobtn_count++;

textBox1.Text = radiobtn_count.ToString();

}
}
}


If this post helps you mark it as answer
Thanks

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

Posted by: Allemahesh on: 9/13/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Can you elaborate you question more clearly?

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

Posted by: Bandi on: 9/13/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Duplicate thread....
http://www.dotnetfunda.com/forums/thread16260-how-many-times-a-radio-button-is-selcted.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Login to post response