944,117 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 117960
  • ASP.NET RSS
Nov 23rd, 2006
0

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
madcloud is offline Offline
4 posts
since Nov 2006
Nov 23rd, 2006
0

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

Cells are zero baseed so the first cell is Cell[0]. Cell[1] is the second column. Maybe that's your issue?
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Nov 24th, 2006
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
madcloud is offline Offline
4 posts
since Nov 2006
Nov 24th, 2006
0

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

I found the solution:


string val = ((Label)DG.SelectedItem.Cells[1].FindControl("id")).Text;
Reputation Points: 10
Solved Threads: 0
Newbie Poster
madcloud is offline Offline
4 posts
since Nov 2006
Dec 27th, 2006
0

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

Click to Expand / Collapse  Quote originally posted by madcloud ...
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.

Reputation Points: 10
Solved Threads: 0
Newbie Poster
zmegh is offline Offline
1 posts
since Dec 2006
Dec 11th, 2009
0
Re: Accessing Datagrid selected row cell value (c# .NET)
Hi...
Try This may this will work

int Rowcount = dgTicket.Rows.Count ;

this.dgTicket.Rows[Rowcount].Cells[1].Text;// add the array item of //which column do u want the text
just add this two lines of code may this will work it out..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kapil Vaichalka is offline Offline
2 posts
since Dec 2009
Feb 4th, 2010
0

vb.net

how to insert the value to the datagrid view
Last edited by spoorti; Feb 4th, 2010 at 9:16 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
spoorti is offline Offline
1 posts
since Feb 2010
Feb 5th, 2010
0
Re: Accessing Datagrid selected row cell value (c# .NET)
Click to Expand / Collapse  Quote originally posted by spoorti ...
how to insert the value to the datagrid view
hi spoorti you can insert the values into into data grid by simple sql command...there are multiple ways to insert the values
simple one is to bind the datasource.

can u show me the exact code what u have written for that i can help you...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kapil Vaichalka is offline Offline
2 posts
since Dec 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Differences between Session and ViewStates?
Next Thread in ASP.NET Forum Timeline: crysatl reports





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC