Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Which row in datagrid is being selected?

Which row in datagrid is being selected?

Scheduled Pinned Locked Moved ASP.NET
questionhelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    desmondling78
    wrote on last edited by
    #1

    Hi, I have a datagrid with some boundcolumns and one templatecolumn. In the template column, i added a dropdownlist. Now on my page, i created a function to handle the SelectedIndexChanged event of the dropdownlist. And so far I am able to trap the event. Protected Sub MyDropdownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim dpl as DropdownList ' How to determine which row's dropdown list did user select? nIndex = 0 dpl = CType(MyDataGrid.Items(nIndex).Cells(7).FindControl("MyDropdownList"), DropDownList) ' Do something with dpl End Sub The problem (as stated in the comment above) is how do I know which row's dropdown list the user selected? I tried to use the selectedindex of the datagrid, but it seems to store garbage values. Thanks

    M 1 Reply Last reply
    0
    • D desmondling78

      Hi, I have a datagrid with some boundcolumns and one templatecolumn. In the template column, i added a dropdownlist. Now on my page, i created a function to handle the SelectedIndexChanged event of the dropdownlist. And so far I am able to trap the event. Protected Sub MyDropdownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim dpl as DropdownList ' How to determine which row's dropdown list did user select? nIndex = 0 dpl = CType(MyDataGrid.Items(nIndex).Cells(7).FindControl("MyDropdownList"), DropDownList) ' Do something with dpl End Sub The problem (as stated in the comment above) is how do I know which row's dropdown list the user selected? I tried to use the selectedindex of the datagrid, but it seems to store garbage values. Thanks

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, To access the DataGridItem object containing the DropDownList, you can do as below: + You first cast the sender object to the DropDownList type to obtain the reference to the DropDownList. + You then cast the NamingContainer property of the DropDownList object to the DataGridItem type. You now have the reference to the DataGridItem instance.

      D 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, To access the DataGridItem object containing the DropDownList, you can do as below: + You first cast the sender object to the DropDownList type to obtain the reference to the DropDownList. + You then cast the NamingContainer property of the DropDownList object to the DataGridItem type. You now have the reference to the DataGridItem instance.

        D Offline
        D Offline
        desmondling78
        wrote on last edited by
        #3

        A million thanks to you. I'd never find that out on my own. Guess I need to read up on MSDN library more. Thanks once again

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups