生成radioButton的方法:
        我们通常为了排版的方便经常会在ItemTemplate列中先放入一个HtmlDataTable,然后再在各个表格(HtmlTableCell)内放入我们需要的控件。但是这里,我们需要你将其中一个表格设为服务器控件(例如:ID为CellForRadio)以便在后台可以获取得到。
        接着就是在数据绑定时向CellForRadio写入Html代码,如下所示:
private void DL_MyReport_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        {
            HtmlTableCell CellForRadio;
                        if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                     
                CellForRadio = (HtmlTableCell) e.Item.FindControl("CellForRadio");                CellForRadio.InnerHtml = "<input type=radio id='Radio"+index+"' runat='server' name='radio')>";
                index++;
                 
            }
        }
然后取值的时候:
private void btn_Execute_Click(object sender, System.EventArgs e)
        {
                 
                for(int i = 0; i<DL.Items.Count; i++)
                {
                   HtmlInputRadioButtonrad_selected = (HtmlInputRadioButton)DL.Items[i].FindControl("CellForRadio").Controls[0];
                   if(rad_selected.Checked)

                   {
                       //DoSomething
                   }
                }
                 
        }
红色的这句有问题了
请问什么回事呢?

解决方案 »

  1.   

    前面代码不关这里的事.只看这里就行了,就是动态在datalist的模版项生成radiobutton,然后获取它的状态的时候出问题了
      

  2.   

    动态生成,动态获取?什么时候生成的?postback后,控件树还有它不?
      

  3.   

    ((HtmlInputRadioButton)DL.Items[i].FindControl("CellForRadio").Controls[0]).text
    试试
      

  4.   

    没有text的话看看点的出value checked没有 反正要点个直出来
      

  5.   

    在Button的click事件里
        protected void Button1_Click(object sender, EventArgs e)
        {
            HyperLink1.NavigateUrl =TextBox1 .Text ;
            HyperLink1.Text = TextBox1.Text;
        }
      

  6.   

    把这个 if(rad_selected.Checked) 改成
    if(rad_selected.checked=="checked")看看
    html控件的表达方式不一样,