Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking 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 Basics 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 June 26th, 2007, 05:12 AM
Authorized User
 
Join Date: May 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to DarkForce
Default Accessing GridView Value

I have a gridview connected to a sqldatasource. now the database contains a table with attibutes like id (unique key) and name etc.
i have several records in that grid. now i want to get a specific id from the table in that database by accessing that in c# code like gridview.rows[2](which does not work) but i need something like that.

Has anyone an idea?

So long
__________________
Ivan
 
Old June 26th, 2007, 06:00 AM
Authorized User
 
Join Date: May 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to DarkForce
Default

I tried the following:

GriedViewRow row = new GridView1.SelectedRow;
Label1.Text= row.Cells[1].Text;

But i do not get any text out of the cell.
Why is that?
So long
 
Old June 26th, 2007, 07:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

you are missing one point, inside a cell could be more than one control (in fact you can have as many as you want).. so your code is going well, but try row.cells[1].findcontrol to find the specific one that have your data...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old June 26th, 2007, 08:54 AM
Authorized User
 
Join Date: May 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to DarkForce
Default

I actually solved the problem another way,
but anyway,

thank you very much for your help.

So long
 
Old June 28th, 2007, 11:14 AM
Registered User
 
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

.my problem solved ...

itz actually this much required to dispaly in textbox. inside GridView1_SelectedIndexChanged i write this much code.

string id = GridView1.SelectedValue.ToString();
Response.Redirect("details.aspx?id=" + id);

and in next page
Textbox1.Text = Request.QueryString["id"].ToString();

thank you very much for your replies





Similar Threads
Thread Thread Starter Forum Replies Last Post
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
Accessing one cell from gridview Aker C# 1 May 22nd, 2008 03:13 PM
Accessing Directory mike_remember ASP.NET 1.0 and 1.1 Professional 6 October 13th, 2006 06:35 AM
Accessing VBScript in C# Diedtje General .NET 1 May 17th, 2005 12:50 PM
Accessing COM port tsimsha Pro VB 6 4 April 29th, 2005 07:23 PM





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