关于Drpodownlist和复选框列表 [英] Regarding Drpodownlist and checkboxlist
问题描述
大家晚上好...............
我有一个包含5或6个项目的下拉列表,一个复选框列表填充在dropdownlist值上.
我的.aspx页面代码如下..
good evening to all..............
I have one dropdownlist with 5 or 6 item and one checkboxlist populate on dropdownlist value.
my .aspx page code is given below..
<asp:DropDownList ID="ddlstDesignation" AutoPostBack="true" runat="server" 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>
<cc1:CheckBoxListExCtrl ID="CheckBoxListExCtrl1" RepeatDirection="Horizontal" RepeatColumns="2" runat="server"> </cc1:CheckBoxListExCtrl>
在选择dropdownlist值时,复选框列表会填充其工作良好....但是当我每次提交页面时都选择dropdownlist值时...
我需要针对此selectedindexchange的JavaScript....
我在.aspx.cs文件后面的代码在下面给出
on selecting of dropdownlist value the checkboxlist is populate its work good....but when i select the dropdownlist value every time its submitt the page ...
i need javascript for this selectedindexchange....
my code behind .aspx.cs file are given below
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);
}
}
我需要javascript slectedindex更改方式,当我选择一个dropdownlist值,然后使用javascript
填充复选框时,
请帮助我...谢谢
i need javascript slectedindex change means when i select a dropdownlist value then populate the checkboxlist using javascript
please help me...thanks
推荐答案
我相信您想与页面进行交互,而无需正确地回发刷新页面?
使用更新面板 [ http://msdn.microsoft.com/en-us/magazine /cc163363.aspx [ ^ ]尽管我建议使用 jQuery [ ^ ]
I believe you want to interact with the page without postback refreshing hte page correct?
You can accomplish this easly, and without JavaScript, using Update Panel[^]
With JavaScript you will need to use AJAX, http://msdn.microsoft.com/en-us/magazine/cc163363.aspx[^] though I would suggest using Jquery[^]
这篇关于关于Drpodownlist和复选框列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!