Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > DataGrid ASP.NET 2.0 C#

Reply
Thread Tools

DataGrid ASP.NET 2.0 C#

 
 
Mike Gleason jr Couturier
Guest
Posts: n/a
 
      09-17-2007
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!

 
Reply With Quote
 
 
 
 
Mike Gleason jr Couturier
Guest
Posts: n/a
 
      09-17-2007
"Mike Gleason jr Couturier" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> 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 !!

 
Reply With Quote
 
 
 
 
Phil H
Guest
Posts: n/a
 
      09-18-2007
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"
<(E-Mail Removed)> wrote:
> "Mike Gleason jr Couturier" <(E-Mail Removed)> wrote in
> messagenews:(E-Mail Removed)...
>
>
>
>
>
> > 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 -



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Datagrid: how cut short display of a long description in a datagrid column Brian K. Williams ASP .Net 0 03-02-2004 08:35 PM
RE: Datagrid: how cut short display of a long description in a datagrid column =?Utf-8?B?U3VyZXNo?= ASP .Net 0 03-02-2004 08:31 PM
datagrid in datagrid BK Kim ASP .Net 1 03-02-2004 06:34 AM
Call Datagrid Command column outside datagrid Dave ASP .Net 0 11-20-2003 11:11 AM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments