|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGrid ASP.NET 2.0 C#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].TextBut I don't want the ID to be displayed... I'm looking for other alternatives. Thanks!
Show quote
"Mike Gleason jr Couturier" <mcouturierMAP***@bmgmultimedia.com> wrote in I finally found a way but I wonder if it's "the" good way :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! > protected void GridViewUsers_SelectedIndexChanged(object sender, EventArgs e) { int userID = (int)GridViewUsers.DataKeys[GridViewUsers.SelectedIndex].Value; [...] } Thanks !! 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 - |
|||||||||||||||||||||||