Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 14th, 2007, 06:28 AM
Authorized User
Join Date: Mar 2007
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!!!

Old March 14th, 2007, 11:23 AM
Friend of Wrox
Join Date: Aug 2006
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.

Old March 14th, 2007, 01:09 PM
Authorized User
Join Date: Mar 2007
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.

Old April 17th, 2007, 02:14 AM
Registered User
Join Date: Apr 2007
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.

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

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