Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get a gridview cell value by column name

Status
Not open for further replies.

dgerdner

Programmer
Mar 30, 2005
41
US
I have a gridview bound to a sqldatasource. The gridview has several columns corresondence to the database column names. However, the only way I've found to grab the value from one of those columns is by knowing the cell index:

GridViewRow gRow = GridView1.Rows[iRow];
TableCell tc = gRow.Cells[14];

Certainly there must be a way I can refer to it by its column name rather than cell index, is there not?
 
I think this is what you are looking for:

dataGridView.Columns[e.ColumnIndex].Name == "ColumnName"

or

DataGridViewCell cell = this.dataGridView[e.ColumnIndex, e.RowIndex];


I hope that helps!


i love chocolate
 
It looks as if you're referring to code in one of the events is that what the "e" variable means?

I'm really looking to do something like this:

sring strFirstName = Grid1.Rows[3].Cells["FirstName"]

where I find a column by it's column name rather than it's Cell index.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top