Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cascading dropDownLists in repeater. DropDownLists with SQL source and add/delete option

What is the trick to implement the following interface in ASP.NET?

repeater

I think the screenshot should explain everything.

  1. Both dropDownLists work on SQL tables. [Categories],[Items] bound with ID_category PK/FK
  2. Number of rows variable (by default 1 row with "Add" button)
  3. Choosing category changes only the content of the dropDownList next to it and the content stays the same when other rows get added/deleted
  4. "Add" button saves current setup and adds new row with either "Select value" or eventually 1st category/1st item selected

How to store previously selected categories/items and the dropDown filtering by category, while adding, changing, deleting items or some other PostBack on website?


What I have tried so far is to use Repeater with DataSet, however I have encountered several different problems:

  • Was unable to preserve the relations between previous dropDowns
  • DropDowns resetting one another
  • 2nd dropDown losing filtering when adding new row

I can post some code but since it doesn't fully work, perhaps a totally different approach would be better. Basically I started with this tutorial. The repeater currently looks like:

<repeater>
<itemtemplate>
  <dropDown DataSource="categoriesDS" 
     value='<%# DataBinder.Eval(Container.DataItem, "Category") %>'.../>
  <dropDown DataSource="itemsDS" 
     value='<%# DataBinder.Eval(Container.DataItem, "Item") %>'.../>
  <button CommandName='<%# DataBinder.Eval(Container.DataItem, "Button") %>' 
     Text='<%# DataBinder.Eval(Container.DataItem, "Button") %>' .../>
</itemtemplate>
</repeater>

Thanks in advance for any suggestions or solutions and I hope it'll be helpful for others.

like image 974
yosh Avatar asked Dec 01 '25 14:12

yosh


1 Answers

Ajax Cascading DropDownlist

It is very simple to use.

like image 190
Sasidharan Avatar answered Dec 03 '25 05:12

Sasidharan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!