• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

Custom Drop Down list

Hi all,

I have a web page which has a datagrid in it. a couple of the columns in this datagrid have a dropdown list. The number of rows present in the grid is dynamic, and changes at runtime quite frequently, but is usually from 5 to 30 or so rows.
Due to client requirements, the rows need to be editable at all times, ie my client is un-willing to accept that the user has to click a button next to a row to bring it to "edit mode" then modify that line, save it, and repeat the process for each row.
One of the dropdown lists has around a hundred and fifty rows in it. an other has around 30 rows. The contents of the drop down lists will not be needing to change during the lifecycle of the form.
I'd like to reduce the html bulk created by repeating the drop-down list multiple times, as each and every dropdown list on the page will present exactly the same options to the client, I'd like the page to download the data once, then render each drop down list at run-time on the client. I've successfully done exactly this for the same application in asp, but now that we've ported the app to .net, it's not quite so simple. I've started looking at creating a Custom Web Control to deal with it, and whilst I'm certain that I'd be able to get it done, I was wondering if anyone else had already done this? Does anyone know of any custom controls available on the web which can do this?
I've not been able to find one, but that doesn't mean there's not one there.

Thanks in advance for your help.
1 Solution
I think your approach is spot on, here are a few resources to help get you started.


Let me know if you need any more help.


If your client is willing to buy this; infragistics has a whole suite of ASP.NET controls, and their WebGrid will do pretty much what you're looking for:


But here are some thoughts with the regular data grid.  If you define the columns with the ddl's as TemplateColumns and then put a ddl in the ItemTemplate, it will be available without having to click an edit button.  Your user could go through row by row, making whatever changes necessary.  Then you would have an update button to post the changes back to the server.

First, make sure you are binding your datagrid to a datatable in a dataset.  You will need to have a data adapter with a select command defined to get the data and fill the datatable.  They key is calling this Fill() method in Page_Load **outside** of the if (!Page.IsPostBack){ } block.  Your page load would look like this:

private void Page_Load(...args here...)
     // get data.

     // check postback.
     if (!Page.IsPostBack)
          // bind grid.

The reason you want the Fill() method called on both the non-postback (the initial load) and on a postback is because when you click the button to update the data changes made by the user you want to do the following:

1) re-fill the datatable.
2) for each row in the grid, resolve the corresponding datarow in the datatable and set the value of the datacolumns with whatever the user has entered by making a selection in the ddls.
3) call the Update() method of the data adapter, passing it the changed datatable.

The first step is accomplished in Page_Load above by putting the Fill() call outside of the postback condition.  #'s 2 and 3 above are then coded in the button's click event, which fires after Page_Load on a postback.

infragistics - good stuff but see the price!!
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

DementedManiacAuthor Commented:
Thanks for your posts.

Aerosaga: I will check out those sites and let you know how I go.

jnhorst: I'll look at the infragistics controls to see if anything will do what I want. Thank you also for your comments re updating the database from the datasource, indeed what you've suggested is a similar approach to what I've implemented. The page is currently working as I described, with each row editable at all times, the optimisation I need is to reduce the bulk of the page by reducing the amount of HTML that is sent to the client. Most of the bulk is currently in the fact that each drop down list and it's respective items have to be sent to the client even though they are identical except for the selected flag on the apropriate item for each list. I'll look at infragistics to see if they have what I need.


recomend point split btwn jnhorst & myself questioner never returned

DementedManiacAuthor Commented:
Hi All,

I apologise for taking so long to get back to you all.

AeroSaga: Thank you for the links, they made for some interesting reading, but unfortunately, did not discuss the custom control building techniques I believe I will need to use to get this working.

jnHorst: From what I saw, the Infragistics controls do not do what I need. Rembember, the outcome I am after is to remove the bulk from the page caused by repeating the ddl's potentially dozens of times without having to cause repeated post-back's each time the user needs to change an entry in a list. I had a look through the options, but did not see anything which will do what I need, If you know of a particular tool they make which does this, I'd certainly apreciate knowing which one.

At this stage, I have purchased "Developing Microsoft ASP.NET server controls and components" and am reading through when I have time so that I can learn how to create the control myself.

Thanks for your suggestions.


PAQed, with points refunded (500)

Community Support Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now