如何计算在c#中选择的单选按钮的数量? [英] how to count no of radio buttons which are selected in c#?
本文介绍了如何计算在c#中选择的单选按钮的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨......
i有一个gridview ....在这个gridview中我在每个gridview行中都有两个单选按钮...
1>必须满足
2>不想见面
如何计算在必须见面和不符合中选择的单选按钮的数量???
解决方案
< blockquote>在Gridview ItemTemplate中添加RadioButton列
< < span class =code-leadattribute> ItemTemplate > < asp:CheckBox ID = ChkMustMeet runat = server < span class =code-attribute> AutoPostBack = True / >
< / ItemTemplate >
CodeBehind:
protected void Page_Load( object sender,EventArgs e)
{
if
(! IsPostBack)
{
BindGrid(); // 网格绑定代码
}
else
{
GetCount();
}
}
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跨度>))经过。
if (isChecked)
{
count ++;
}
}
返回计数;
}
如果您需要每次检查并取消选中使用选择更改的活动,请相应地更改以上内容。
希望这会有所帮助......
你好,
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 ++;
}
}
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"???
解决方案
Add RadioButton Columns in the Gridview ItemTemplate
<ItemTemplate><asp:CheckBox ID="ChkMustMeet" runat="server" AutoPostBack="True" /> </ItemTemplate>
CodeBehind:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); //Grid Binding code } else { GetCount(); } }
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...
Hello,
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++; } }
这篇关于如何计算在c#中选择的单选按钮的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文