Filter data of a dropdownlist in datagrid

Discussion in 'ASP .Net' started by =?Utf-8?B?SnVhbmpv?=, Nov 9, 2005.

  1. 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?
    =?Utf-8?B?SnVhbmpv?=, Nov 9, 2005
    #1
    1. Advertising

  2. 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.

    --
    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?
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Nov 9, 2005
    #2
    1. Advertising

  3. 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?
    =?Utf-8?B?SnVhbmpv?=, Nov 10, 2005
    #3
  4. 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).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?
    >
    >
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Nov 10, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RyanG
    Replies:
    0
    Views:
    488
    RyanG
    Aug 23, 2004
  2. mr2_93
    Replies:
    1
    Views:
    3,597
    mr2_93
    Oct 2, 2005
  3. =?Utf-8?B?SnVhbmpv?=

    GridView: Filter DropDownList for another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,296
    =?Utf-8?B?SnVhbmpv?=
    Dec 29, 2005
  4. zax75
    Replies:
    1
    Views:
    1,096
  5. Cirene

    How filter dropdownlist data

    Cirene, May 28, 2008, in forum: ASP .Net
    Replies:
    8
    Views:
    551
    Milosz Skalecki [MCAD]
    May 28, 2008
Loading...

Share This Page