Link to home
Start Free TrialLog in
Avatar of DementedManiac
DementedManiac

asked on

Custom Drop Down list

Hi all,

Background:
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.
Avatar of AerosSaga
AerosSaga

I think your approach is spot on, here are a few resources to help get you started.

http://www.microsoft.com/belux/nl/msdn/community/columns/jtielens/datagrid.mspx
http://www.dotnetjunkies.com/Article/587D1BFA-60CD-4C2D-8DFB-011F0402666C.dcik
http://aspnet.4guysfromrolla.com/articles/031704-1.aspx

Let me know if you need any more help.

Regards,

Aeros
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:

http://www.infragistics.com

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.
     dataAdapter.Fill(dsDataset.tblDataTable);

     // check postback.
     if (!Page.IsPostBack)
     {
          // bind grid.
          dataGrid.DataBind();
     }
}

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.

John
infragistics - good stuff but see the price!!
Avatar of DementedManiac

ASKER

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.

Regards,

DM
recomend point split btwn jnhorst & myself questioner never returned

Aeros
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.

D.Maniac


ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial