Solved

Custom Drop Down list

Posted on 2004-09-24
9
302 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:DementedManiac
9 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12141997
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
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12147084
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
0
 

Expert Comment

by:trentk2
ID: 12156309
infragistics - good stuff but see the price!!
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:DementedManiac
ID: 12156500
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
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12365697
recomend point split btwn jnhorst & myself questioner never returned

Aeros
0
 

Author Comment

by:DementedManiac
ID: 12396680
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


0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12434152
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now