Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 14th, 2007, 06:28 AM
Authorized User
Join Date: Mar 2007
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JoinTTT
Default Getting Data from selected row in gridview

My issue is related to getting data in gridview when I selected a row. Because Always the value comes "".
Firstly I bind the dataset to gridview in code-behind. I didn't use sqldatasource. and in html code about gridview is below:

<asp:GridView ID="grd_getdata" runat="server" OnSelectedIndexChanged="grd_getdata_SelectedIndexC hanged"
     AutoGenerateColumns="False" DataKeyNames="No" EnableSortingAndPagingCallbacks="True">
            <asp:BoundField DataField="No" HeaderText="No" ReadOnly="True" />

and selectedindexchangedevent code is;

protected void grd_getdata_SelectedIndexChanged(object sender, EventArgs e)
        GridViewRow row = grd_getdata.SelectedRow;
        Session["aksesuar"] = row.Cells[0].Text;

So the value of row.Cells[0].Text always comes empty. On the other hand I see the value on gridview. Why couldn't I get the value?

I hope you know the answer!!!

  #2 (permalink)  
Old March 14th, 2007, 11:23 AM
Friend of Wrox
Join Date: Aug 2006
Location: , , .
Posts: 131
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kherrerab Send a message via Yahoo to kherrerab

you could go easy way. Set many datakeynames and then when you select the row and the selectedindexchanged runs you get the different values of the selectedindex or selectedvalue items.

  #3 (permalink)  
Old March 14th, 2007, 01:09 PM
Authorized User
Join Date: Mar 2007
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JoinTTT

I found the solution. I convert the column I want to Template Column, so

In SelectedIndexChanged event,
GridViewRow row = grd_getdata.SelectedRow;
Label lbl = (Label)row.FindControl("Label1");
this.Label1.Text = lbl.Text;

It works well done.

  #4 (permalink)  
Old April 17th, 2007, 02:14 AM
Registered User
Join Date: Apr 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

i had the same problem as JohnTTT,
and didnt really understand his solution... but heres mine:

string s = GridView1.SelectedRow.Cells[2].Text;

the '2' seems to give me my first column... i have no idea why.

ow well. it works. have fun.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass gridview selected row msbsam ASP.NET 2.0 Basics 1 March 4th, 2008 09:17 AM
Data Binding - Editing GridView Row Data desk_star BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 7 December 30th, 2007 11:07 AM
How to update a selected row from gridview control ryan.webb ASP.NET 2.0 Professional 1 December 28th, 2007 05:21 AM
Edit selected row of datagrid Mukesh Kumar ASP.NET 1.0 and 1.1 Basics 1 April 26th, 2007 03:54 PM
Deleting selected row in ListBox YoungFools Excel VBA 1 April 19th, 2007 09:14 AM

All times are GMT -4. The time now is 05:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.