我用如下办法在程序中动态生成DataGrid,也如愿成功了,但我要对模块列的RadioButtonList的选择情况进行统计,却想不出办法,高手请指教。
(原程序较长,只列出动态生成模块列程序:)
public void Button1_Click_1(object sender, System.EventArgs e)
{ .....
               for (int inti=0; inti<Convert.ToInt32(TextBox1.Text.ToString());inti++)
{
TableRow myrow=new TableRow();
TableCell mycell=new TableCell();
                                              ......
dgc_option.HeaderText="是否合标准";
dgc_option.HeaderStyle.Height=new Unit(30);
dgc_option.ItemStyle.BackColor=ColorTranslator.FromHtml("#F7F7F7");
dgc_option.ItemStyle.Width=new Unit(186);
dgc_option.ItemTemplate=myColumn;
DataGrid1.Columns.Add(dgc_option);

DataGrid1.DataBind();
mycell.Controls.Add(DataGrid1);
                                                .......
public class ColumnTemplate : ITemplate      
{
public void InstantiateIn(Control container)
{

RadioButtonList myradio=new RadioButtonList();
myradio.RepeatDirection=RepeatDirection.Horizontal;
myradio.Items.Add("合格");
myradio.Items.Add("不合格");
container.Controls.Add(myradio);
}

解决方案 »

  1.   

    是submit后在服务器端统计吗?
      

  2.   

    确实是个比较难办的问题,
    有个思路,但不是很好,
    把DataGrid的数据源保存在Session,每次postback都重新动态生成、重新绑定;
    通过radiobuttonlist的SelectIndexChange事件更改Session的相应行
     public class ColumnTemplate : ITemplate     
        {
            public void InstantiateIn(Control container)
            {            RadioButtonList myradio=new RadioButtonList();
                myradio.RepeatDirection=RepeatDirection.Horizontal;
                myradio.Items.Add("合格");
                myradio.Items.Add("不合格");
                myradio.SelectedIndexChanged+=new EventHandler(myradio_SelectedIndexChanged);
                container.Controls.Add(myradio);
            }        private void myradio_SelectedIndexChanged(object sender, EventArgs e)
            {
                System.Data.DataTable tb =  System.Web.HttpContext.Current.Session["tb"] as System.Data.DataTable;
                RadioButtonList rb = sender as RadioButtonList;
                string tmp = rb.SelectedValue;
                ....
            }
        }
      

  3.   

    我并不需要radioButtonlist的selectecvalue,而是对选择情况进行统计
      

  4.   

    Radiobuttonlist myradio=(RadioButtonList)dataGrid1.items[i].cell[j].findcontrol(radio)