Home All Groups Group Topic Archive Search About
Author
17 Sep 2007 7:37 PM
Mike Gleason jr Couturier
Hi,

I display a list of users (my SELECT contains the name and the ID of the
users) in a DataGrid.

The users display fine (single column).
On the SelectedIndexChanged event, I want to retreive the user ID.

Is there a way to attach the user ID on a particular row ?

I already tried to display the ID on a second column and get the ID by doing
:
GridViewUsers.SelectedRow.Cells[1].Text
But I don't want the ID to be displayed... I'm looking for other
alternatives.

Thanks!

Author
17 Sep 2007 7:47 PM
Mike Gleason jr Couturier
Show quote
"Mike Gleason jr Couturier" <mcouturierMAP***@bmgmultimedia.com> wrote in
message news:3AAADA21-96F8-4B1C-AC87-05EB2874365C@microsoft.com...
> Hi,
>
> I display a list of users (my SELECT contains the name and the ID of the
> users) in a DataGrid.
>
> The users display fine (single column).
> On the SelectedIndexChanged event, I want to retreive the user ID.
>
> Is there a way to attach the user ID on a particular row ?
>
> I already tried to display the ID on a second column and get the ID by
> doing :
> GridViewUsers.SelectedRow.Cells[1].Text
> But I don't want the ID to be displayed... I'm looking for other
> alternatives.
>
> Thanks!
>


I finally found a way but I wonder if it's "the" good way :

    protected void GridViewUsers_SelectedIndexChanged(object sender,
EventArgs e)
    {
        int userID =
(int)GridViewUsers.DataKeys[GridViewUsers.SelectedIndex].Value;
        [...]
    }

Thanks !!
Author
18 Sep 2007 8:06 PM
Phil H
Hi Mike

Glad you asked about this. I've been confronted with this sort of
problem too recently.

Your solution:

int userID =
int)GridViewUsers.DataKeys[GridViewUsers.SelectedIndex].Value;

could be a bit more direct with:

int userID = (int) GridViewUsers.SelectedValue;

HTH

On 17 Sep, 20:47, "Mike Gleason jr Couturier"
<mcouturierMAP***@bmgmultimedia.com> wrote:
Show quote
> "Mike Gleason jr Couturier" <mcouturierMAP***@bmgmultimedia.com> wrote in
> messagenews:3AAADA21-96F8-4B1C-AC87-05EB28743***@microsoft.com...
>
>
>
>
>
> > Hi,
>
> > I display a list of users (my SELECT contains the name and the ID of the
> > users) in a DataGrid.
>
> > The users display fine (single column).
> > On the SelectedIndexChanged event, I want to retreive the user ID.
>
> > Is there a way to attach the user ID on a particular row ?
>
> > I already tried to display the ID on a second column and get the ID by
> > doing :
> > GridViewUsers.SelectedRow.Cells[1].Text
> > But I don't want the ID to be displayed... I'm looking for other
> > alternatives.
>
> > Thanks!
>
> I finally found a way but I wonder if it's "the" good way :
>
>     protected void GridViewUsers_SelectedIndexChanged(object sender,
> EventArgs e)
>     {
>         int userID =
> (int)GridViewUsers.DataKeys[GridViewUsers.SelectedIndex].Value;
>         [...]
>     }
>
> Thanks !!- Hide quoted text -
>
> - Show quoted text -

AddThis Social Bookmark Button