Dynamic DropDownLists in a DataGrid

G

G Stark

Couldn't say if this has ever been covered here before...

All the articles that I have found on the internet cover "Static
DropDownLists" in a DataGrid, but what about "Dynamic DropDownLists" in a
DataGrid. I hope I can intrigue you enough to read a little further and
suggest a solution.

How does one implement a dynamic DropDownList in a DataGrid? By this I mean
each row has a unique list for it's DropDownList.

Well you could say why not use a DataRepeater and build your list manually.
Yes, I can implement it that way, but I already have the DataGrid coded and
working, and it would be nice if I could continue to use the DataGrid. So
is there a way to do this?

The data might look something like the sample below. The dataset used by
the datagrid returns multiple rows for products, as in product, product
description, rate, and term. The price goes in the DataTextField and the
term in goes in the DataValueField of the DropDownList.

One idea would be to populate the list using a function that returns the
dataset. So, how to pass two unique variables of row data (Catalog &
Product) to this function. That is the part I am not clear on. There is no
URL field for a Template Column.

Catalog Product Product Description Rate Term
1014 HP-C7845A 32MB 100MHz SDRAM for HP-CLJ8500DN C7845A 9.00 30
1014 HP-C7845A 32MB 100MHz SDRAM for HP-CLJ8500DN C7845A 3.00 720
1014 HP-C7845A 32MB 100MHz SDRAM for HP-CLJ8500DN C7845A 2.00 900
1014 HP-C7845A 32MB 100MHz SDRAM for HP-CLJ8500DN C7845A 1.00 1080
1014 DELL-311-0818 128MB Memory Module for Latitude CPx 11.00 30
1014 DELL-311-0818 128MB Memory Module for Latitude CPx 3.00 720
1017 DELL-311-2539 128MB SDRAM Non-ECC for GX110 Dell units 311-2539
12.00 30
1017 DELL-311-2539 128MB SDRAM Non-ECC for GX110 Dell units 311-2539
3.00 900

Becomes:
Product Product Description Rate/Term
HP-C7845A 32MB 100MHz SDRAM for HP-CLJ8500DN C7845A 9.00/30 <- Dropdown
w/4 items
DELL-311-0818 128MB Memory Module for Latitude CPx 11.00/30 <- Dropdown
w/2 items
DELL-311-2539 128MB SDRAM Non-ECC for GX110 Dell units 311-2539 12.00/30 <-
Dropdown w/2 items

Your consideration is much appreciated.

Greg Stark
 
D

Drew Robbins

You can have parameters on your code-behind function. For example, if
your function is:

public string[] GetDropDownItems(object Catalog, object Product)
{
}

Then in your ASPX file:

<EditItemTemplate>
<asp:DropDownList ... DataSource='<%#
GetDropDownItems(DataBinder.Eval(Container, "DataItem.Catalog"),
DataBinder.Eval("DataItem.Product")) %>' />
</EditItemTemplate>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top