Q: datagrid values with column name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
string colVal =((TextBox)e.Item.Cells.Controls[0]).Text;

this is how I reach column value in a grid:
how can I reach with the column name?
some value should be int, some date, how should I read them?
Thanks,
Jim.
 
Make a simple utility function that will take a column name as a parameter,
loop through the Columns collection and return the index of the column with
matching name.

Eliyahu
 
can you give me example?

Eliyahu Goldin said:
Make a simple utility function that will take a column name as a parameter,
loop through the Columns collection and return the index of the column with
matching name.

Eliyahu

JIM.H. said:
Hello,
string colVal =((TextBox)e.Item.Cells.Controls[0]).Text;

this is how I reach column value in a grid:
how can I reach with the column name?
some value should be int, some date, how should I read them?
Thanks,
Jim.

 
C#:
static public System.Web.UI.WebControls.TableCell CellByName
(System.Web.UI.WebControls.DataGridItem item, string name)
{
System.Web.UI.WebControls.DataGrid grid = item.Parent.Parent as
System.Web.UI.WebControls.DataGrid;
for (int col = 0; col < item.Cells.Count; col++)
if (grid.Columns[col].HeaderText == name)
return item.Cells[col];
// not found
return null;
}


--
Eliyahu

JIM.H. said:
can you give me example?

Eliyahu Goldin said:
Make a simple utility function that will take a column name as a parameter,
loop through the Columns collection and return the index of the column with
matching name.

Eliyahu

JIM.H. said:
Hello,
string colVal =((TextBox)e.Item.Cells.Controls[0]).Text;

this is how I reach column value in a grid:
how can I reach with the column name?
some value should be int, some date, how should I read them?
Thanks,
Jim.

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top