如何调用占位符包含的checkboxlist的selectedIndexChange

时间:2011-12-30 11:13:15

标签: asp.net

我正在填写下面的复选框列表。 如何调用SelectedIndexChanged占位符包含的复选框列表事件。

代码:

public void loadTracks()
{
    try
    {
        ConfigurationDB objConfig = new ConfigurationDB();
        DataSet ds = objConfig.GetTracks(Convert.ToInt32(
                                 ddl.SelectedValue.ToString()));
        CheckBoxList CbxList  = new CheckBoxList();
        // CheckBoxList CbxListtemp = new CheckBoxList();
        CbxList.ID = "Chk";
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            CbxList.Items.Add(new ListItem(ds.Tables[0].Rows[i]["Name"]
                        .ToString(), ds.Tables[0].Rows[i]["ID"].ToString()));
            //CbxListtemp.Items.Add(
               // new ListItem(ds.Tables[0].Rows[i]["Track_Name"].ToString()
               //, ds.Tables[0].Rows[i]["ID"].ToString()));
        }
        // CbxList = CbxListtemp;
        ph.Controls.Add(CbxList);
    }
    catch(Exception ex)
    {
        throw ex
    }
}

1 个答案:

答案 0 :(得分:1)

您需要订阅如下所示的事件处理程序(如果这是您的意思):

        public void loadTracks()
        {
            try
            {
               ConfigurationDB objConfig = new ConfigurationDB();
               DataSet ds = objConfig.GetTracks(Convert.ToInt32(ddl.SelectedValue.ToString()));
               CheckBoxList CbxList  = new CheckBoxList();
                CbxList.SelectedIndexChanged += new EventHandler(CbxList_SelectedIndexChanged);
               // CheckBoxList CbxListtemp = new CheckBoxList();
               CbxList.ID = "Chk";
               for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
               {
                   CbxList.Items.Add(new ListItem(ds.Tables[0].Rows[i]["Name"].ToString(), ds.Tables[0].Rows[i]["ID"].ToString()));
                   //CbxListtemp.Items.Add(new ListItem(ds.Tables[0].Rows[i]["Track_Name"].ToString(), ds.Tables[0].Rows[i]["ID"].ToString()));
               }
               // CbxList = CbxListtemp;
               ph.Controls.Add(CbxList);
            }
            catch(Exception ex)
            {
              throw ex;
            }
        }

        void  CbxList_SelectedIndexChanged(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }