Click here to Skip to main content
15,917,455 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<itemtemplate>
<asp:dropdownlist id="cmdDept" runat="server" text="<%# Bind("DeptAbbr") %>"
="" datasourceid="DeptSqlDataSource" datatextfield="DeptAbbr" datavaluefield="DeptAbbr" width="64px">

<asp:sqldatasource id="DeptSqlDataSource" runat="server" connectionstring="<%$ ConnectionStrings:PMSConnectionString %>"



="" selectcommand="SELECT [DeptAbbr] FROM [DeptMaster] where DeptAbbr =<%cmbDeptAbbr.SelectedItem.Text%> ORDER BY [DeptCode]">



What I have tried:

 SelectCommand="SELECT [DeptAbbr] FROM [DeptMaster] where DeptAbbr =<%cmbDeptAbbr.SelectedItem.Text%> ORDER BY [DeptCode]">
                                         

in the cmbDeptAbbr.SelectedItem.Text its show error , am I defined correctly ?
Posted
Updated 31-May-19 3:07am

You have not provided sufficient information to your problem but looks like you are trying to create cascading dropdown function. Refer the below links for more details on it -

Cascading A DropDownList With Another DropDownList in ASP.Net[^]
 
Share this answer
 
Comments
Member 10194266 31-May-19 0:20am    
Hi Vinod
My code is below:

<asp:templatefield headertext="Dept">
<itemtemplate>
<asp:dropdownlist id="cmdDept" runat="server" text="<%# Bind("DeptAbbr") %>"
="" datasourceid="DeptSqlDataSource" datatextfield="DeptAbbr" datavaluefield="DeptAbbr" width="64px">

<asp:sqldatasource id="DeptSqlDataSource" runat="server" connectionstring="<%$ ConnectionStrings:PMSConnectionString %>"
="" selectcommand="SELECT [DeptAbbr] FROM [DeptMaster] ORDER BY [DeptCode]">

<headerstyle font-size="9pt" horizontalalign="Left" verticalalign="Top">
<itemstyle horizontalalign="Left" verticalalign="Top">





-----------------------

SelectCommand="SELECT [DeptAbbr] FROM [DeptMaster] ORDER BY [DeptCode]">
in this query i want to used cmbDeptAbbr.SelectedItem.Text how can i used in the here
Add a ControlParameter to your data source control:
ControlParameter Class (System.Web.UI.WebControls) | Microsoft Docs[^]
ASP.NET
<asp:SqlDataSource id="DeptSqlDataSource" runat="server"
    connectionstring="<%$ ConnectionStrings:PMSConnectionString %>"
    selectCommand="SELECT [DeptAbbr] FROM [DeptMaster] WHERE DeptAbbr = @DeptAbbr ORDER BY [DeptCode]"
>
<SelectParameters>
    <asp:ControlParameter
        Name="DeptAbbr"
        ControlId="cmbDeptAbbr"
        PropertyName="SelectedValue"
    />
</SelectParameters>
</asp:SqlDataSource>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900