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>
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);
}
}
}
when i select the dropdownlist value its not work..
please help me..
i am using visual studio 2008 with c#