我用如下办法在程序中动态生成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);
}
(原程序较长,只列出动态生成模块列程序:)
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);
}
解决方案 »
- 采集--google源码有什么规律?
- text赋值问题!
- 向大家讨教个问题:跨服务器备份表有什么好的实现方法?!?
- 如果有一些引用标记存在于命名中!刚不会重命于这些引用,要继续吗?
- word-break:break-all 未知的属性名?
- 谁可以给我一个网站功能描述文档
- 关于小偷问题
- 如何用 TREEVIEW 做个这样的选框
- 关于WMI应用中的拒绝访问的问题
- 为什么不能用中文
- 各个大侠救命啊,帮帮小弟一下:如何让Xml文件中的内容,自动换行;也就是说原样输入,然后原样输出。
- ===============================我把一段字输入,然后写到xml文件中,怎样让替换让他按原样输出。====================================
有个思路,但不是很好,
把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;
....
}
}