By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

Filter data of a dropdownlist in datagrid

P: n/a
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?
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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/Da...olsEvents.aspx and then
you can figure step3 easily.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Juanjo" wrote:
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?

Nov 19 '05 #2

P: n/a
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).Cel ls(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?
Nov 19 '05 #3

P: n/a
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

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Juanjo" wrote:
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).Cel ls(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?

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.