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. How do I pass a gridview index to an sqldatasource select command?

How do I pass a gridview index to an sqldatasource select command?

Scheduled Pinned Locked Moved ASP.NET
questiondatabase
4 Posts 3 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.
  • F Offline
    F Offline
    FionaDM
    wrote on last edited by
    #1

    How do I pass a gridview index, as calculated by gridview RowCommand, to an sqldatasource select command? My code is appended. I have a gridview with a Buttonfield with Commandname 'SelectStaff'. On SelectStaff I want to calculate the index of the current row. I have done this successfully using Gridview OnRowCommand event. See method GridView1_RowCommand. I then want to pass the calulated index to the an SqldataSource select command so I can populate a FormView with data whose index is the same as the gridview index. I'm trying to use the Sqldatasource Selectingevent to pick up the index value but with no success. See method SqlDataSource2_Selecting. P.S. I can't use the the GridView CommandField Select as it's already been used. Here's my code: ID:
    Name:
    private int index = 0; protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "SelectStaff") { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32

    R M 2 Replies Last reply
    0
    • F FionaDM

      How do I pass a gridview index, as calculated by gridview RowCommand, to an sqldatasource select command? My code is appended. I have a gridview with a Buttonfield with Commandname 'SelectStaff'. On SelectStaff I want to calculate the index of the current row. I have done this successfully using Gridview OnRowCommand event. See method GridView1_RowCommand. I then want to pass the calulated index to the an SqldataSource select command so I can populate a FormView with data whose index is the same as the gridview index. I'm trying to use the Sqldatasource Selectingevent to pick up the index value but with no success. See method SqlDataSource2_Selecting. P.S. I can't use the the GridView CommandField Select as it's already been used. Here's my code: ID:
      Name:
      private int index = 0; protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "SelectStaff") { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32

      R Offline
      R Offline
      Reza Raad
      wrote on last edited by
      #2

      you must use ITEM_DATABOUND event to handle it,MSDN help has brief description about it.

      1 Reply Last reply
      0
      • F FionaDM

        How do I pass a gridview index, as calculated by gridview RowCommand, to an sqldatasource select command? My code is appended. I have a gridview with a Buttonfield with Commandname 'SelectStaff'. On SelectStaff I want to calculate the index of the current row. I have done this successfully using Gridview OnRowCommand event. See method GridView1_RowCommand. I then want to pass the calulated index to the an SqldataSource select command so I can populate a FormView with data whose index is the same as the gridview index. I'm trying to use the Sqldatasource Selectingevent to pick up the index value but with no success. See method SqlDataSource2_Selecting. P.S. I can't use the the GridView CommandField Select as it's already been used. Here's my code: ID:
        Name:
        private int index = 0; protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "SelectStaff") { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32

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

        Hi there, In the event handler of the RowCommand event of the GridView control, you simply call the DataBind method of the FormView control, and as a result of that the Selecting event of the second SqlDataSource control gets fired.

        F 1 Reply Last reply
        0
        • M minhpc_bk

          Hi there, In the event handler of the RowCommand event of the GridView control, you simply call the DataBind method of the FormView control, and as a result of that the Selecting event of the second SqlDataSource control gets fired.

          F Offline
          F Offline
          FionaDM
          wrote on last edited by
          #4

          Thanks - that works great. I had a workaround assigning the index to a (hidden)label and then assigning the selected index value to the value of the label control. Your method is I think the best way! Thanks Maj

          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