数据列表之外的asp.net DropDownList的OnSelectedIndexChanged

本文关键字:net DropDownList OnSelectedIndexChanged asp 数据 列表 | 更新日期: 2023-09-27 18:26:18

我有一个包含CheckBoxList的DataList,我在selectedindexchanged上过滤数据列表。问题是当我从下拉列表中选择值时,我无法从数据库中获取检查的值CCD_ 2项目计数为0

这是代码

  protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string GroupValue;
        if (DropDownList1.SelectedValue.ToString().IsEmpty()) { GroupValue = null; } else { GroupValue = DropDownList1.SelectedValue.ToString(); }
        if (pageMode == PageMode.Update)
        {
            int rowID = int.Parse(GrdUsers.GetRowValues(GrdUsers.FocusedRowIndex, "ID").ToString());
            //ConnectionLayer cn = new ConnectionLayer();
            //DataTable dt = cn.ExecutQuery("PagesSys", new object[] { 0, DropDownList1.SelectedItem.Text.ToString() });
            //dlstPages.DataSource = dt;
            //dlstPages.DataBind();
            BindOption(rowID);
        }
  private void BindOption(int UserID)
{
    try
    {
        if (pageMode == PageMode.Update)
        {
            if (DropDownList1.SelectedItem.Value != "-1")
            {
                dlstPages.DataSource = ViewState["FunctionOption"];
                dlstPages.DataBind();
                if (dlstPages.Items.Count > 0)
                {
                    for (int i = 0; i < dlstPages.Items.Count; i++)
                    {
                        DataTable dt = new Users().UserPrivilege(UserID, int.Parse(dlstPages.DataKeys[i].ToString()));
                        if (dt.Rows.Count > 0)
                        {
                            dt.PrimaryKey = new DataColumn[] { dt.Columns["OptionId"] };
                            CheckBoxList chklist = (CheckBoxList)dlstPages.Items[i].FindControl("chkOption");
                            for (int j = 0; j < chklist.Items.Count; j++)
                            {
                                if (dt.Rows.Find(chklist.Items[j].Value) != null)
                                {
                                    chklist.Items[j].Selected = true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    catch (Exception ex)
    {
    }


}

数据列表之外的asp.net DropDownList的OnSelectedIndexChanged

您需要使用函数的参数来获取下拉列表对象,然后才能找到所选的值。类似于:

DropDownList ddl= (DropDownList)sender;
var value = ddl.SelectedValue.ToString();