我正在尝试在链接按钮单击事件上触发单选按钮检查更改事件,但它会转到页面加载并且单选按钮检查更改事件不会触发。
protected void Page_Load(object sender, EventArgs e)
{
string Query = "select Q101004,Q101005 from Q101 where Q101001<110000013";
DataTable dt = ExecuteDataset(Query).Tables[0];
ViewState["dt"] = dt;
Table t = new Table();
TableRow r = new TableRow();
t.Rows.Add(r);
TableCell c = new TableCell();
lnkbtn = new LinkButton();
r.Cells.Add(c);
lnkbtn.Text = "Click Here";
lnkbtn.Visible = true;
lnkbtn.CommandName = "Test";
lnkbtn.CommandArgument = "Hi";
lnkbtn.ID = "Hi";
PlaceHolder2.Controls.Add(lnkbtn);
for (int i = 0; i < dt.Rows.Count; i++)
{
rb = new RadioButton();
rb.AutoPostBack = true;
rb.ID = "m" +i;
rb.GroupName = "a";
rb.Text = dt.Rows[0][0].ToString();
CbxList = new CheckBoxList();
CbxList.ID = "Cbx"+i;
CbxList.Enabled = false;
CbxList.RepeatDirection = RepeatDirection.Horizontal;
CbxList.RepeatColumns = 2;
CbxList.CellPadding = 10;
CbxList.CellSpacing = 5;
CbxList.RepeatLayout = RepeatLayout.Table;
options = dt.Rows[0][1].ToString().Split('~');
PlaceHolder2.Controls.Add(new LiteralControl("<br/>"));
for (int j = 0; j < options.Length; j++)
{
CbxList.Items.Add(new ListItem(options[j], options[j]));
}
PlaceHolder2.Controls.Add(rb);
PlaceHolder2.Controls.Add(CbxList);
if (i ==0)
rb.CheckedChanged += new EventHandler(rb_CheckedChanged);
else
lnkbtn.Click += new EventHandler(lnkbtn_Click);
}
}
void lnkbtn_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)ViewState["dt"];
lnkbtn = (LinkButton)PlaceHolder2.FindControl("Hi");
string str=((LinkButton)sender).CommandArgument;
//lnkbtn.Enabled = true;
if (lnkbtn.ID == str)
{
rb = new RadioButton();
rb.AutoPostBack = true;
rb.ID = "m";
rb.GroupName = "a";
rb.Text = dt.Rows[0][0].ToString();
CbxList = new CheckBoxList();
CbxList.ID = "Cbx";
CbxList.Enabled = false;
CbxList.RepeatDirection = RepeatDirection.Horizontal;
CbxList.RepeatColumns = 2;
CbxList.CellPadding = 10;
CbxList.CellSpacing = 5;
CbxList.RepeatLayout = RepeatLayout.Table;
options = dt.Rows[0][1].ToString().Split('~');
PlaceHolder2.Controls.Add(new LiteralControl("<br/>"));
for (int i = 0; i < options.Length; i++)
{
CbxList.Items.Add(new ListItem(options[i], options[i]));
}
PlaceHolder2.Controls.Add(rb);
PlaceHolder2.Controls.Add(CbxList);
if (lnkbtn.CommandName == "Test")
{
rb.CheckedChanged += new EventHandler(rb_CheckedChanged);
}
}
}