I have two databse table
1: Sector
2: Project
In Sector table there is 4 sectors(sector1,sector2,sector3,sector4)
and if sector1 is selected then then related project shown
I have two databse table
1: Sector
2: Project
In Sector table there is 4 sectors(sector1,sector2,sector3,sector4)
and if sector1 is selected then then related project shown
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Mar 9, 2023, 6:12 AM
@Garima use this
Naimish MakwanaPosted Mar 9, 2023, 6:07 AM
Hello Garima,
The "GetData" method referred to in the code snippet I provided is a custom method that you need to implement yourself. This method is responsible for retrieving data from the database and returning it as a DataTable.
Thanks
Naimish Makwana
Garima BansalPosted Mar 9, 2023, 6:03 AM
Naimish Makwana
I am getting an error in GetData method "The name "GetData" doesnt exists in current context
Naimish MakwanaPosted Mar 9, 2023, 5:53 AM
Hello Garima,
To cascade the dropdown from the database, you can follow these steps:
1. Retrieve the data from the database table "Sector" and bind it to the dropdown "ddlsector".
You can do this in the Page_Load event of your code-behind file as follows:
Here, "GetData" is a custom function that returns a DataTable containing the data retrieved from the database using the specified SQL query. You can implement this function as per your database connection and query.
2 Handle the SelectedIndexChanged event of "ddlsector" and retrieve the related projects from the database table "Project" and bind them to the dropdown "ddlproject".
You can do this as follows:
Here, "SectorID" and "ProjectID" are assumed to be the primary keys of "Sector" and "Project" tables, respectively, and "SectorID" is a foreign key in the "Project" table referencing the "Sector" table. Also, "ProjectName" and "SectorName" are assumed to be the display field names in the "Project" and "Sector" tables, respectively.
Finally, don't forget to add the OnSelectedIndexChanged event handler for "ddlsector" in the markup as follows:
Here, AutoPostBack="True" ensures that the page is posted back to the server when the dropdown selection is changed, triggering the SelectedIndexChanged event.
Thanks
Naimish Makwana
Vishal YelvePosted Mar 9, 2023, 5:51 AM
Please refer below link.
https://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx
Jignesh KumarPosted Mar 9, 2023, 5:48 AM
Hello Grishma,
Please try below url which has step by step explanation for cascade dropdown,
https://www.c-sharpcorner.com/UploadFile/009464/cascading-one-dropdownlist-with-other-dropdownlist-in-asp-ne/
https://www.aspsnippets.com/Articles/Populate-Cascading-DropDownList-from-Database-in-ASPNet-Example.aspx