在往datagrid中动态添加控件,并设定触发事件,但是不能实现,请高手指教哪里出了问题!!!!代码如下
------------
SqlCommand sc=new SqlCommand("procedure",sqlConnection);
sc.CommandType=CommandType.StoredProcedure;
SqlParameter sp=new SqlParameter("@id",SqlDbType.Int);
sp.Value=Values;
sc.Parameters.Add(sp);
sqlConnection1.Open();
SqlDataReader sd=sc.ExecuteReader();Label []lblQ=new Label[count];//定义Label控件组RadioButtonList []tblA=new RadioButtonList[count];//定义RadioButtonList控件组
//
System.Web.UI.Control pl=DataGrid.Items[index].FindControl("Panel1");int i=0;
//
while(sd.Read())
{
lblQ[i]=new Label();
lblAWD[i]=new Label();
tblA[i]=new RadioButtonList();
ListItem liA=new ListItem("1","1");
ListItem liB=new ListItem("2","2");
ListItem liC=new ListItem("3","3");
ListItem liD=new ListItem("4","4");
tblA[i].Items.Add(liA);
tblA[i].Items.Add(liB);
tblA[i].Items.Add(liC);
tblA[i].Items.Add(liD);
tblA[i].Attributes.Add("runat","server");
tblA[i].RepeatDirection=RepeatDirection.Horizontal;
tblA[i].AutoPostBack=true;
                  // 给控件添加事件  ------但是不运行
tblA[i].SelectedIndexChanged+=new EventHandler(Checked_Click); pl.Controls.Add(tblA[i]);
i=i+1;
}
sd.Close();
sqlConnection.Close();
---------------------------
public void  Checked_Click()
{.................}

解决方案 »

  1.   

    public void  Checked_Click() //方法签名不对
      

  2.   

    要有一个sender和一个e,
    让vs给你自动生成一下
      

  3.   

    sender 可以对象可以判断选择了哪个控件。
      

  4.   

    public void  Checked_Click()
    {.................}
    -------------------------
    改为
    public void  Checked_Click(object sender, System.EventArgs e)
    {.................}试试
      

  5.   

    public void  Checked_Click(object sender, System.EventArgs e)
    {}