Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi...

i have a gridview....in this gridview i have two radio buttons in every gridview row...
1> must meet
2> dont want to meet
how to count no of radio buttons which are selected in "must meet" & "dont meet"???
Posted
Updated 26-Dec-13 18:15pm
v2
Comments
TrushnaK 27-Dec-13 0:06am    
how to count no of radio buttons which are selected in c#?
improve your question what you want exactly.
Gaurav Makwana 27-Dec-13 0:15am    
int i = 0;
if(checkbox1.checked)
{
count i everytime and do i++)
}
Sergey Alexandrovich Kryukov 27-Dec-13 0:35am    
What have you tried so far?
—SA

Add RadioButton Columns in the Gridview ItemTemplate

XML
<ItemTemplate><asp:CheckBox ID="ChkMustMeet" runat="server" AutoPostBack="True" />
                   </ItemTemplate>


CodeBehind:
C#
protected void Page_Load(object sender, EventArgs e)
 {
  if 
  (!IsPostBack) 
    { 
      BindGrid(); //Grid Binding code
    }
  else 
    { 
      GetCount(); 
    }
  }


C#
private int GetCount()
    {
        int count = 0;
        GridViewRow row = null;
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            row =GridView1.Rows[i];
            bool isChecked = ((RadioButton)row.FindControl("ChkMustMeet")).Checked;
            if (isChecked)
            {
                count++;
            }
        }
       return count; 
    }

Change the above accordingly if you need each time check and uncheck use select changed event.

Hope this helps...
 
Share this answer
 
v2
Hello,

C#
int meet=0,dont_meet=0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
 RadioButton rb1 = (RadioButton)GridView1.Rows[i].FindControl("rd_meet");
 RadioButton rb2 = (RadioButton)GridView1.Rows[i].FindControl("rd_dontmeet");
 if (rb1.Checked)
 { 
    meet++;
 }
 if (rb2.Checked)
 { 
    dont_meet++;
 }
}
 
Share this answer
 
Comments
Member 10276220 27-Dec-13 3:05am    
i have used radiobuttonlist...in this case how do i do it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900