从动态添加的radiobuttons获取值 [英] Get values from dynamically added radiobuttons

查看:297
本文介绍了从动态添加的radiobuttons获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家

我在表格中动态添加单选按钮。然后我怎样才能在该表中检查单选按钮值



这里我发布我的ocde



< pre lang =c#> int j = 0 ;
int k = 0 ;
string l = 0;
foreach var q in MyList)
{
if (q.OptionGroup == 单选按钮
{
TableRow tr = new TableRow();
tr.Font.Bold = true ;
TableCell tc = new TableCell();
Label lblquestion = new Label();
tc.Height = 10 ;
lblquestion.Text = q.Name;
tc.Controls.Add(lblquestion);
tr.Controls.Add(tc);
for int i = 0 ; i < Mylist.Length; i ++)
{
TableRow tr1 = new TableRow();
TableCell cl = new TableCell();
TableCell cl2 = new TableCell();
Label txt = new Label();
txt.Text = AnswerName;
txt.ID = Lableanswer + k;
cl.Height = 10 ;
cl2.Height = 10 ;
RadioButton raid = new RadioButton();
raid.ID = raid + j;
raid.GroupName = l;
cl.Controls.Add(txt);
cl2.Controls.Add(raid);
tr.Controls.Add(cl);
tr.Controls.Add(cl2);

j ++;
k ++;
table1.Controls.Add(tr1);
}
table1.Controls.Add(tr);

}
l = l + 1 ;
}
}





这里我们每行都有多个单选按钮..如何查看单选按钮每行的价值..



请帮帮我..



在此先感谢..

解决方案

基本上有两种方式:



1.

循环表,检查包含单选按钮的单元格,看它是否被选中。



2.

为radiobutton添加一个事件处理程序on creation(每个radiobutton的相同处理程序)。



 raid.Clicked + = ... 





单击时,发送方对象可以转换为RadioButton对象(unboxed),并在某种列表中更新值。 (例如,Dictionary< string,>其中string是按钮名称)


Hi experts
i did adding radio buttons dynamically in a table. then how can i get checked radio button values in that table

here i post my ocde

int j = 0;
            int k = 0;
            string l = "0";
            foreach (var q in MyList)
            {
                if (q.OptionGroup == "Radio Buttons")
                {
                        TableRow tr = new TableRow();
                        tr.Font.Bold = true;
                        TableCell tc = new TableCell();
                        Label lblquestion = new Label();
                        tc.Height = 10;
                        lblquestion.Text = q.Name;
                        tc.Controls.Add(lblquestion);
                        tr.Controls.Add(tc);
                        for (int i = 0; i < Mylist.Length; i++)
                        {
                            TableRow tr1 = new TableRow();
                            TableCell cl = new TableCell();
                            TableCell cl2 = new TableCell();
                            Label txt = new Label();
                            txt.Text = AnswerName;
                            txt.ID = "Lableanswer" + k;
                            cl.Height = 10;
                            cl2.Height = 10;
                            RadioButton raid = new RadioButton();
                            raid.ID = "raid" + j;
                            raid.GroupName = l;
                            cl.Controls.Add(txt);
                            cl2.Controls.Add(raid);
                            tr.Controls.Add(cl);
                            tr.Controls.Add(cl2);
                           
                            j++;
                            k++;
                            table1.Controls.Add(tr1);
                        }
                        table1.Controls.Add(tr);

                    }
                    l = l + 1;
                }
}



here we have multiple radiobutton in each row.. how can i get checked radio button values in each row..

please help me..

Thanks in advance..

解决方案

Basically there are two ways:

1.
Loop the table, check the cell that contains the radiobutton to see if it is checked or not.

2.
Add an event handler to the radiobutton on creation (the same handler for each radiobutton).

raid.Clicked += ... 



When clicked, the sender object can be casted to a RadioButton object ("unboxed") and the value updated in a list of some kind. (eg. Dictionary<string,> where string is the button name)


这篇关于从动态添加的radiobuttons获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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