| | |
Accessing Datagrid selected row cell value (c# .NET)
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 4
Reputation:
Solved Threads: 0
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
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
Cells are zero baseed so the first cell is Cell[0]. Cell[1] is the second column. Maybe that's your issue?
•
•
Join Date: Dec 2006
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
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.
![]() |
Similar Threads
- How to change the color of selected row of an HTML table without using CSS or Javascr (VB.NET)
- How To highlight a row or a column in a datagrid....? (ASP.NET)
- Help please, how to appear a combo box in DataGrid while user click a cell? (Visual Basic 4 / 5 / 6)
- Deleting a Row From A DataGrid (VB.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Horizontal display of data on Repeater control in asp.net
- Next Thread: How to close window
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax appliances asp asp.net beginner box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox class compatible confirmationcodegeneration content contenttype control countryselector courier css dataaccesslayer database datagrid datagridview datalist deadlock deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv forms gridview gudi homeedition iis javascript jquery list listbox menu mssql multistepregistration nameisnotdeclared news novell objects opera order problem radio ratings redirect registration relationaldatabases reportemail rotatepage search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview validatedate validation vb.net videos virtualdirectory vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming wizard xml xsl






