Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please any one let me know how can i get records in listview on dropdown selection where both the dropdownlist is databound to sqldatasource. and on selection of dropdown i need to display the list of records in listview so that i can bind this records with gridview
Posted
Updated 24-May-19 0:26am
Comments
[no name] 24-May-19 7:07am    
https://forums.asp.net/t/1357900.aspx?SelectedIndexChanged+of+a+DropDownList+which+is+inside+a+ListView

Fro displaying Record on the basis of dropdown selected index you need to do like this....


1) Attach a selected index change event to your drop down...

2) write a method or function fro selecting records from database with a where cause to filter resulted data... select query like this....
SQL
SELECT * FROM PRODUCT WHERE PRODUCT_ID = @PRODUCTID


3) then call that function inside you dropdown selected index change event and pass a value which you want to pass for select query parameter... here i use a productID as a dropdown data value filed and product name as drop down data text filed... so my code like this...

C#
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    int productid = Convert.ToInt32(ddlReportSelection.SelectedValue.ToString());
    loadDataToListBox(productid);
}       
private void loadDataToListBox(int productid)
{
    string query = "SELECT * FROM PRODUCT WHERE PRODUCTID = @PRODUCTID";
    ///code for fill data table or data set goes here....
    ///
    lstview.DataSource = ds;
    lstview.DataBind();
}


i hope it will solve your problem....
 
Share this answer
 
Comments
priti2010 8-Nov-11 5:08am    
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConstr %>" SelectCommand="SELECT * FROM [Servers]">
<asp:DropDownList ID="ddlServer" runat="server" CssClass="dropdownlistLarge" Font-Size="10"
AutoPostBack="true" OnSelectedIndexChanged="ddlServer_SelectedIndexChanged" DataTextField="Server_Name"
DataValueField="Server_ID" DataSourceID="SqlDataSource1">


Collapse | Copy Code
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConstr %>" SelectCommand="SELECT * FROM [Services]">
<asp:DropDownList ID="ddlService" runat="server" CssClass="dropdownlistLarge" OnSelectedIndexChanged="ddlService_SelectedIndexChanged" AutoPostBack="true" Font-Size="10"
DataSourceID="SqlDataSource2" DataTextField="Service_Name"
DataValueField="Service_ID">
These are my two dropdownlist where in if i select ddlServer i should get list of Services applicable in a format like

Collapse | Copy Code
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:sqlConstr %>"
SelectCommand="SELECT Service_ID,Service_Name from Services where Applicable_Servers like '%1,%' ">

and if second dropdownlist ddlService then i should get list of applicable servers
so how can i write select index code for this and this listview values to bind to my main table
 
Share this answer
 
XML
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConstr %>" SelectCommand="SELECT * FROM [Servers]"></asp:SqlDataSource>
   <asp:DropDownList ID="ddlServer" runat="server" CssClass="dropdownlistLarge" Font-Size="10"
            AutoPostBack="true" OnSelectedIndexChanged="ddlServer_SelectedIndexChanged" DataTextField="Server_Name"
             DataValueField="Server_ID" DataSourceID="SqlDataSource1">
                      </asp:DropDownList>


XML
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConstr %>" SelectCommand="SELECT * FROM [Services]"></asp:SqlDataSource>
   <asp:DropDownList ID="ddlService" runat="server" CssClass="dropdownlistLarge" OnSelectedIndexChanged="ddlService_SelectedIndexChanged" AutoPostBack="true" Font-Size="10"
    DataSourceID="SqlDataSource2" DataTextField="Service_Name"
           DataValueField="Service_ID"></asp:DropDownList>


These are my two dropdownlist where in if i select ddlServer i should get list of Services applicable in a format like
XML
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
          ConnectionString="<%$ ConnectionStrings:sqlConstr %>"
          SelectCommand="SELECT Service_ID,Service_Name from Services where Applicable_Servers like '%1,%' ">
      </asp:SqlDataSource>


and if second dropdownlist ddlService then i should get list of applicable servers
so how can i write select index code for this and this listview values to bind to my main table
 
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