关于更新面板和下拉列表 [英] Regarding update panel and dropdownlist

查看:66
本文介绍了关于更新面板和下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

下午好,

我正在使用Visual Studio 2008的更新面板和脚本管理器通过dropdownlist填充checkboxlist,这意味着当我选择dropdownlist值然后根据此值checkboxlist populate

我的.aspx代码在下面给出.

hi all,

good afternoon,

i am using the update panel and script manager of visual studio 2008 for populating checkboxlist through dropdownlist means when i choose a dropdownlist value then according to this value checkboxlist populate

my .aspx code is given below.

<asp:Content ID="Content1" ContentPlaceHolderID="ReportFormContents" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering ="true">
    </asp:ScriptManager>
 <div>
 <asp:DropDownList ID="ddlstDesignation"  runat="server" AutoPostBack="false" Width="193px"

    onselectedindexchanged="ddlstDesignation_SelectedIndexChanged" Height="25px">
     <asp:ListItem Value="--Select--">--Select--</asp:ListItem>
      <asp:ListItem Value="1">National Sales Manager </asp:ListItem>
      <asp:ListItem Value="2">Region Manager</asp:ListItem>
     <asp:ListItem Value="3">Branch Manager</asp:ListItem>
      <asp:ListItem Value="4">Area Manager</asp:ListItem>
      <asp:ListItem Value="5">Supervisor</asp:ListItem>
      <asp:ListItem Value="6">Salesman</asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />
     <asp:UpdatePanel ID="UpdatePanel1" runat="server">

  <ContentTemplate>
   <cc1:CheckBoxListExCtrl ID="CheckBoxListExCtrl1" runat="server" >
    </cc1:CheckBoxListExCtrl>
  </ContentTemplate>
   <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlstDesignation" EventName="SelectedIndexChanged" />
    </Triggers>
      </asp:UpdatePanel>
        </div>
</asp:Content>




以及下面给出的我的aspx.cs页面.





and my aspx.cs page given below.


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class testCheckboxlist : System.Web.UI.Page
{
    SqlConnection ConnDeemah = new SqlConnection();
    public string Cmd = "";
    public string Value = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        string connectionString = (string)ConfigurationSettings.AppSettings["ConnectionString"];
        ConnDeemah.ConnectionString = connectionString;
    }

    private void BindCheckboxList(string designation)
    {
        if (designation == "1")
        {
            ConnDeemah.Open();
            SqlDataReader nsmDr;
            Cmd = "SELECT Convert(varchar, NSM.NationalSalesManagerCode)+ ' - ' + NSM.NationalSalesManagerName + ' / ' + C.CountryName As NationalSalesManagerName, NSM.NationalSalesManagerCode FROM NationalSalesManager NSM INNER JOIN Country C ON NSM.NationalSalesManagerCode = C.NationalSalesManagerCode ORDER BY NationalSalesManagerName";
            SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
            nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
            CheckBoxListExCtrl1.DataSource = nsmDr;
            CheckBoxListExCtrl1.DataTextField = "NationalSalesManagerName";
            CheckBoxListExCtrl1.DataValueField = "NationalSalesManagerCode";
            CheckBoxListExCtrl1.DataBind();
        }
        else if (designation == "2")
        {
            ConnDeemah.Open();
            SqlDataReader nsmDr;
            Cmd = "SELECT Convert(varchar, RMgr.RegionManagerCode)+ ' - ' + RMgr.RegionManagerName + ' / ' + RMst.RegionMstName As RegionManagerName, RMgr.RegionManagerCode FROM RegionManager RMgr INNER JOIN RegionMaster RMst  ON RMgr.RegionManagerCode = RMst.RegionManagerCode ORDER BY RMgr.RegionManagerCode";
            SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
            nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
            CheckBoxListExCtrl1.DataSource = nsmDr;
            CheckBoxListExCtrl1.DataTextField = "RegionManagerName";
            CheckBoxListExCtrl1.DataValueField = "RegionManagerCode";
            CheckBoxListExCtrl1.DataBind();
        }
        else if (designation == "3")
        {
            ConnDeemah.Open();
            SqlDataReader nsmDr;
            Cmd = Cmd = "SELECT Convert(varchar, BMgr.BranchManagerCode)+ ' - ' + BMgr.BranchManagerName + ' / ' + DMst.DepotName  As BranchManagerName, BMgr.BranchManagerCode FROM BranchManager BMgr INNER JOIN DepotMaster DMst ON BMgr.BranchManagerCode = DMst.BranchManagerCode ORDER BY BMgr.BranchManagerCode";
            SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
            nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
            CheckBoxListExCtrl1.DataSource = nsmDr;
            CheckBoxListExCtrl1.DataTextField = "BranchManagerName";
            CheckBoxListExCtrl1.DataValueField = "BranchManagerCode";
            CheckBoxListExCtrl1.DataBind();
        }
        else if (designation == "4")
        {
            ConnDeemah.Open();
            SqlDataReader nsmDr;
            Cmd = Cmd = Cmd = "SELECT Convert(varchar, AreaManagerCode)+ ' - ' + AreaManagerName As AreaManagerName, AreaManagerCode FROM AreaManager ORDER BY AreaManagerCode";
            SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
            nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
            CheckBoxListExCtrl1.DataSource = nsmDr;
            CheckBoxListExCtrl1.DataTextField = "AreaManagerName";
            CheckBoxListExCtrl1.DataValueField = "AreaManagerCode";
            CheckBoxListExCtrl1.DataBind();
        }
        else if (designation == "5")
        {
            ConnDeemah.Open();
            SqlDataReader nsmDr;
            Cmd = Cmd = Cmd = Cmd = "SELECT Convert(varchar, SupervisorCode)+ ' - ' + SupervisorName As SupervisorName, SupervisorCode FROM Supervisor ORDER BY SupervisorCode";
            SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
            nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
            CheckBoxListExCtrl1.DataSource = nsmDr;
            CheckBoxListExCtrl1.DataTextField = "SupervisorName";
            CheckBoxListExCtrl1.DataValueField = "SupervisorCode";
            CheckBoxListExCtrl1.DataBind();
        }
        else if (designation == "6")
        {
            ConnDeemah.Open();
            SqlDataReader nsmDr;
            Cmd = Cmd = Cmd = Cmd = Cmd = "SELECT Convert(varchar, SalesmanCode)+ ' - ' + SalesmanName1 As SalesmanName, SalesmanCode FROM Salesman ORDER BY SalesmanCode";
            SqlCommand RCMD = new SqlCommand(Cmd, ConnDeemah);
            nsmDr = RCMD.ExecuteReader(CommandBehavior.CloseConnection);
            CheckBoxListExCtrl1.DataSource = nsmDr;
            CheckBoxListExCtrl1.DataTextField = "SalesmanName";
            CheckBoxListExCtrl1.DataValueField = "SalesmanCode";
            CheckBoxListExCtrl1.DataBind();
        }
    }

    protected void ddlstDesignation_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlstDesignation.SelectedValue == "1")
        {
            CheckBoxListExCtrl1.Visible = true;
            BindCheckboxList(ddlstDesignation.SelectedValue);
        }
        else if (ddlstDesignation.SelectedValue == "2")
        {
            CheckBoxListExCtrl1.Visible = true;
            BindCheckboxList(ddlstDesignation.SelectedValue);
        }
        else if (ddlstDesignation.SelectedValue == "3")
        {
            CheckBoxListExCtrl1.Visible = true;
            BindCheckboxList(ddlstDesignation.SelectedValue);
        }
        else if (ddlstDesignation.SelectedValue == "4")
        {
            CheckBoxListExCtrl1.Visible = true;
            BindCheckboxList(ddlstDesignation.SelectedValue);
        }
        else if (ddlstDesignation.SelectedValue == "5")
        {
            CheckBoxListExCtrl1.Visible = true;
            BindCheckboxList(ddlstDesignation.SelectedValue);
        }
        else if (ddlstDesignation.SelectedValue == "6")
        {
            CheckBoxListExCtrl1.Visible = true;
            BindCheckboxList(ddlstDesignation.SelectedValue);
        }
    }
}




当我选择下拉列表值时,它不起作用..

请帮帮我..

我正在将Visual Studio 2008与c#




when i select the dropdownlist value its not work..

please help me..

i am using visual studio 2008 with c#

推荐答案

一起使用,您需要将DropDownList的 AutoPostBack 设置为 True .
You need to set AutoPostBack of the DropDownList to True.


这篇关于关于更新面板和下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆