2011-11-24 47 views
0

我在asp:table内部动态创建单选按钮。我想获取所选单选按钮的ID。检索asp中动态单选按钮控件的值:表

  1. 如何检查控制型
  2. 如何获得其ID。

    RadioButton radioButton = new RadioButton(); 
        radioButton.ID = id + "RadioButton"; 
        radioButton.ToolTip = text; 
        radioButton.Attributes.Add("id", id); 
        radioButton.GroupName = categoryID + "Questions"; 
        radioButton.EnableViewState = true; 
        radioButton.AutoPostBack = true; 
        radioButton.Checked = isSelected; 
        radioButton.CssClass = style; 
    
        TableCell cell = new TableCell(); 
        cell.HorizontalAlign = HorizontalAlign.Left; 
        cell.Controls.Add(radioButton); 
        TableRow row = new TableRow(); 
        row.Cells.Add(cell); 
        table.Rows.Add(row); 
    
+0

你想在服务器端回发时获得身份证? – sll

+0

看到这个帖子:[通过类型获取控件的所有子控件的位图](http://stackoverflow.com/q/7555309/485076) – sll

回答

1

解决方案。我发布这个解决方案来帮助别人。

 RadioButton rb = new RadioButton();    
     foreach (TableRow tr in QuestionTable.Controls) 
     { 
      foreach (TableCell tc in tr.Controls) 
      { 
       if (tc.Controls[0] is RadioButton) 
       { 
        rb = (RadioButton)tc.Controls[0]; 
        if (rb.Checked) 
        { 
         string aa = rb.ID; 
        } 
        break; 
       } 
      }    
     } 
0

你为什么不使用jQuery。

指定THR单选按钮一类

遍历“各自”功能使用“每个”功能

那么类,检查是否(这)对象被饰以“选择”或“检查'财产。