Accessing Datagrid selected row cell value (c# .NET)

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 4
Reputation: madcloud is an unknown quantity at this point 
Solved Threads: 0
madcloud madcloud is offline Offline
Newbie Poster

Accessing Datagrid selected row cell value (c# .NET)

 
0
  #1
Nov 23rd, 2006
Hi all!

I would like some help for getting a value out of a selected row of a datagrid.

To do this i used the following code but it returns an empty string
(DG is my datagrid)

string val = DG.SelectedItem.Cells[1].Text;
Response.Write("*"+val+");

The rouput of this its: **
although there is a value on the cell.
The datagrid is created and filled in the Page_Load when !Page.IsPostBack and the above code is called when a button is pressed.

Does anyone know how to fix this?

Best regards

George
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Accessing Datagrid selected row cell value (c# .NET)

 
0
  #2
Nov 23rd, 2006
Cells are zero baseed so the first cell is Cell[0]. Cell[1] is the second column. Maybe that's your issue?
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 4
Reputation: madcloud is an unknown quantity at this point 
Solved Threads: 0
madcloud madcloud is offline Offline
Newbie Poster

Re: Accessing Datagrid selected row cell value (c# .NET)

 
0
  #3
Nov 24th, 2006
No unfortunately its not this. I have tried to display something using all the indexes but it doesn work.
In the select event I have also tried using:
e.Item.Cells[1].Text; and yet again its displayed empy.
Any ideas?

Best regardes,

George
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 4
Reputation: madcloud is an unknown quantity at this point 
Solved Threads: 0
madcloud madcloud is offline Offline
Newbie Poster

Re: Accessing Datagrid selected row cell value (c# .NET)

 
0
  #4
Nov 24th, 2006
I found the solution:


string val = ((Label)DG.SelectedItem.Cells[1].FindControl("id")).Text;
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1
Reputation: zmegh is an unknown quantity at this point 
Solved Threads: 0
zmegh zmegh is offline Offline
Newbie Poster

Re: Accessing Datagrid selected row cell value (c# .NET)

 
0
  #5
Dec 27th, 2006
Originally Posted by madcloud View Post
I found the solution:


string val = ((Label)DG.SelectedItem.Cells[1].FindControl("id")).Text;

here is how.

this is the event function

privatevoid Select_myDataGrid(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
lblLabel.Text = e.Item.Cells[1].Text;

}
e.Item.Cells[1].Text;

it tested it and it worked like a charm.

Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC