Getting the value of a single cell in a datagrid
-
This is definitely Monday. I have an Excel worksheet that I am trying to get the contents of a DataGrid into. worksheet.Cells(2, 1) = StatusGrid.Column(1).Item(1) It would be nice if it were that simple. I was thiking of casting the datagrid into a table, but for reasons that are too cosmic to go into here, that is not possible at this time. So... the question is.. Using VB.Net (ASP), how in the world does one reference a Cell in a datagrid?
-
This is definitely Monday. I have an Excel worksheet that I am trying to get the contents of a DataGrid into. worksheet.Cells(2, 1) = StatusGrid.Column(1).Item(1) It would be nice if it were that simple. I was thiking of casting the datagrid into a table, but for reasons that are too cosmic to go into here, that is not possible at this time. So... the question is.. Using VB.Net (ASP), how in the world does one reference a Cell in a datagrid?
Close... StatusGrid.Items(1).Cells(1).Text()
-
Close... StatusGrid.Items(1).Cells(1).Text()
-
So far so good. That works on bound columns beautifully. Some of the other columns are rendered as Template columns. How would you perform the same operation on a column as defined here: Thanks again in advance for all of your help. -Ray
-
Depends on whats in em.. If you have textbox's etc in them, you'll want to look at the controls collection of the cell, or use the FindControl method to just grab it.
That seems to be the problem: //-- This works well: (just a bound column) For i = 0 To StatusGrid.Items.Count - 1 worksheet.Cells(i + 2, 1) = StatusGrid.Items(i).Cells(1).Text() Next //-- but when I use: (Tries to get a Template Column) For i = 0 To StatusGrid.Items.Count - 1 worksheet.Cells(i + 2, 2) = StatusGrid.Items(i).FindControl("lblDateAdded").ToString() Next ...the appropriate cell text reads: "System.Web.UI.WebControls.Label" It doesn't seem to be finding the lblDateAdded control using the above method. Do I need to be casting it? -- modified at 18:55 Monday 3rd October, 2005