Datagrid Editing Using Dropdown List Question

lorena

Centurion
Joined
Oct 23, 2003
Messages
134
Location
Phoenix, Arizona
I have a table that populates a datagrid for a user to edit.
When the user clicks "Edit", one of the columns needs to be a dropdown list so only certain choices will be entered in the database.
The list only has 5 values and I want to call a function which creates an array or arraylist to populate the dropdown.
I am having a problem because the dropdown control doesn't actually exist until the user clicks Edit so I am having problems referring to it by code.
Here is the template code for the template column:
<asp:TemplateColumn HeaderText="Type">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Type") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList Runat="server" ID="ddlType" DataValueField="Type" DataSource="<%# GetTypes() %>">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
And this is the function code(so far):
Function GetTypes() As DataSet
Dim oTypes As New ArrayList()
oTypes.Add("PROD")
oTypes.Add("TOOL")
oTypes.Add("REWORK")
oTypes.Add("SHOP AID")
oTypes.Add("PROTO")

End Function

How do I bind this array to the dropdown control? I cannot do it inline with the control because I need to set the selected value for the dropdown to the value contained in the cell (and the unedited record).
I hope I am making sense.
Any help would be appreciated.
Thanks in advance
 
Well try this, change the declaration to this

.... DataSource="<%# GetTypes(DataBinder.Eval(Container.DataItem, "Type") ) %>

then in the GetTypes function

change

Function GetTypes() As DataSet

to

Function GetTypes() As ArrayList

...
then at the bottom of the function
...
return OTypes

End Function
 
Sorry I have just realised that the selected item is not going to selected.

But the "return oTypes" should get the list control populated.

Maybe you can add something like this to select item

...SelectedIndex="<%# GetTypesIndex(DataBinder.Eval(Container.DataItem, 'Type') ) %>"
 
Back
Top