我正在创建动态数据表并将其分配给 gridview。我需要为表格的每一行添加一个单选按钮。但我试过了,但无法让它工作。
if (dt == null)
{
dt = new DataTable("Shedules");
DataColumn c0 = new DataColumn("Radio", typeof(RadioButton));
DataColumn c1 = new DataColumn("SID", typeof(System.Int32));
DataColumn c2 = new DataColumn("FID", typeof(System.Int32));
DataColumn c3 = new DataColumn("FROM", typeof(System.String));
dt.Columns.Add(c0);
dt.Columns.Add(c1);
dt.Columns.Add(c2);
dt.Columns.Add(c3);
dt.PrimaryKey = new DataColumn[] { c1 };
}
foreach (AgentPortal.SriLankanWebService.Shedule shedule in air1Response)
{
DataRow dr = dt.NewRow();
RadioButton rb1 = new RadioButton();
rb1.GroupName = "depart";
rb1.ID = shedule.Sid.ToString();
dr["Radio"] = rb1;
dr["SID"] = (int)shedule.Sid;
dr["FID"] = (int)shedule.Fid;
dr["FROM"] = (String)shedule.FromLocation;
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();