Filter data of a dropdownlist in datagrid

G

Guest

I have a datagrid with two temnplate columns. When a row is in edit mode the
each template columns show a dropdownlist (its datasource is a dataview).

I need to filter data of second dropdownlist when the user select an item of
first dropdownlist.

I have the event OnSelectedIndexChanged of first dropdownlist. I try to use
de rowfilter property of dataview with no exit.

Is posible to do this? How?
 
G

Guest

1- while handling the OnSelectedIndexChanged of the first dropdownlist get a
reference to the NamingContainer (the selected datagriditem)
2- use FindControl within the selected datagriditem to get a reference to
the second dropdownlist
3- filter the dataview and rebind to the dropdownlist.

I have an example that can help you with steps 1-2
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx and then
you can figure step3 easily.
 
G

Guest

OK Phillip, many many thanks.

Now my 2 dropdownlists works ok, but now my problem is with the second
dropdownlist and the property selectedvalue.

I need to set this property, I try with
CType(dgEquiArt.Items(dgEquiArt.EditItemIndex).Cells(7).Controls(1),
DropDownList).SelectedValue="XXXXX"

in event OnSelectedIndexChanged of first dropdownlist, but causes an error

El argumento especificado está fuera del intervalo de valores válidos.
Nombre del parámetro: 4730601

In english: The argument specified is out of valid interval values.
Parameter name 4730601

Could you help me?
 
G

Guest

Hi Juanjo,

For easier debugging during development I recommend that you expand that one
line of code to be like this:

Dim ddl As DropDownList
Dim dgi As DataGridItem
dgi = CType(dgEquiArt.Items(dgEquiArt.EditItemIndex), DataGridItem)
'or if you are writing this in the method that handles the
DataGrid.EditCommand
'event use the datagrid item from the passed parameter of type
'DataGridCommandEventArgs like this:
'dgi = e.Item
ddl = dgi.FindControl("SecondDropDownListID") 'use here the ID of the
dropdownlist
If ddl Is Nothing Then
Throw New Exception("Could not find the second dropdwonlist")
Else
ddl.ClearSelection()
Dim oListItem As ListItem = ddl.Items.FindByValue("xxxx")
If Not oListItem Is Nothing Then oListItem.Selected = True
End If
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top