5 Replies - 2130 Views - Last Post: 14 December 2012 - 09:21 PM Rate Topic: -----

#1 robgw3  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 138
  • Joined: 23-February 12

How do you get the selected cell of a gridview?

Posted 14 December 2012 - 12:09 PM

I am just curious about something, if i have a gridview that has rows of buttons how do i get the id of a button that is clicked?

Like say there are 4 rows of 4 buttons each, how can i tell whether i am clicking on button 1 in row 1 instead of button 1 in row 4? I've searched online but i cant seem to find a good answer for this. (I dont have code to include because i havent made anything, i am just trying to figure this out before i get started.)

Is This A Good Question/Topic? 0
  • +

Replies To: How do you get the selected cell of a gridview?

#2 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 244
  • Joined: 17-January 08

Re: How do you get the selected cell of a gridview?

Posted 14 December 2012 - 12:29 PM

You should try doing it first based off of the GridView info found on MSDN.

If you are still having issues after you have made a good faith attempt at accomplishing what you have asked, post your code up and I'm sure someone will help you out. Simply asking "How do you do [something]?" will get you nowhere on this forum 99.99% of the time.
Was This Post Helpful? 0
  • +
  • -

#3 robgw3  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 138
  • Joined: 23-February 12

Re: How do you get the selected cell of a gridview?

Posted 14 December 2012 - 01:10 PM

I dont like MSDN because it is incredably hard to understand them, I find it easiest to understand when I can see an actual example, not just a bunch of lines that can be put into code. In fact most sites like MSDN are often useless to me which is why I asked here in the first place.
Was This Post Helpful? 0
  • +
  • -

#4 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 244
  • Joined: 17-January 08

Re: How do you get the selected cell of a gridview?

Posted 14 December 2012 - 02:05 PM

View Postrobgw3, on 14 December 2012 - 12:10 PM, said:

I dont like MSDN because it is incredably hard to understand them, I find it easiest to understand when I can see an actual example, not just a bunch of lines that can be put into code. In fact most sites like MSDN are often useless to me which is why I asked here in the first place.


I don't know if you know this or not but if you click on any of the properties listed on MSDN in the link I provided, it shows examples of how to use them. Check out the SelectedRow property.
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,074
  • Joined: 02-July 08

Re: How do you get the selected cell of a gridview?

Posted 14 December 2012 - 02:11 PM

No one ever started out liking the MSDN documents, but they are still your research tool. The nice thing is you can look at all the events and methods and explore them. The notes will start to make more sense if you keep trying.
Was This Post Helpful? 0
  • +
  • -

#6 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: How do you get the selected cell of a gridview?

Posted 14 December 2012 - 09:21 PM

The easiest way to deal with buttons in a gridview is by setting the CommandName Property of the button and then using the GridView's OnRowCommand event.

void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
    // If multiple buttons are used in a GridView control, use the
    // CommandName property to determine which button was clicked.
    if(e.CommandName=="Add")
    {
       // Do something           
    }
    if (e.CommandName=="Remove")
    {
       // Do something else
    }
  }



The above example would handle the event raised by a button with a CommandName of "Add" or another event raised by a button with a CommandName of "Remove". Some CommandNames are automatically processed by the GridView, such as "Insert", "Update" and "Delete". If you are creating a custom CommandName it is best to avoid using one of these to avoid some unforeseen side effects.

And you should pay attention to the other comments, MSDN may not be the easiest to navigate but it is still an invaluable resource

This post has been edited by Nakor: 14 December 2012 - 09:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1