Accessing the value of a cell in a datagrid

  • Thread starter amazon otter via .NET 247
  • Start date
A

amazon otter via .NET 247

Hi,
I've been researching in how to do this for 3 days now. I'mdisplaying a datagrid, DATAGRID1, that has for instance 3columns and 5 rows. The column headers are Employee, Day1, andDay2. Each column may or may not have string data in them.
------DATAGRID1-----------------
Employee Day1 Day2
John S
Sam A
Joe D
Jen F
Nick T
--------------------------------

The row values are Linkbuttons. So when a user clicks on say,"S", for John under Day1, my datagrid does an OnItemCommandevent to a Sub called "Process_OnItemCommand".

I need for this Sub to give me the Cell index that it resides in.I know how to get the row index by using, e.item.itemindex, butI really need to know how to get the Cell(Column) index. Allthe examples I've seen so far have syntax like, LABELx.text =CType(e.Item.Cells(1).FindControl("LABELy"), label).text, whereCells(1) actually means something to them.

I do not have the luxury of knowing which cell was selected or doI? Am I missing something? Is their a way of finding theColumn Index. The reason I am trying to do this is so that Ican take the value that was selected and remove it from theDataset and eventually the re-painted datagrid.

Thanks

From: amazon otter
 
P

Prodip Saha

You may not have to use the Cell reference. Here is an example that may
help---
LinkButton lnkButton= (LinkButton) e.Item.FindControl("Name of the link
button");

//If there is a link button with the name above exist then the variable
lnkButton will be
//mapped.

if(lnkButton!=null)
{
//do something;
}

We should NEVER rely on the positioning.
Prodip
Hi,
I've been researching in how to do this for 3 days now. I'm displaying a
datagrid, DATAGRID1, that has for instance 3 columns and 5 rows. The column
headers are Employee, Day1, and Day2. Each column may or may not have
string data in them.
------DATAGRID1-----------------
Employee Day1 Day2
John S
Sam A
Joe D
Jen F
Nick T
--------------------------------

The row values are Linkbuttons. So when a user clicks on say, "S", for John
under Day1, my datagrid does an OnItemCommand event to a Sub called
"Process_OnItemCommand".

I need for this Sub to give me the Cell index that it resides in. I know
how to get the row index by using, e.item.itemindex, but I really need to
know how to get the Cell(Column) index. All the examples I've seen so far
have syntax like, LABELx.text = CType(e.Item.Cells(1).FindControl("LABELy"),
label).text, where Cells(1) actually means something to them.

I do not have the luxury of knowing which cell was selected or do I? Am I
missing something? Is their a way of finding the Column Index. The reason
I am trying to do this is so that I can take the value that was selected and
remove it from the Dataset and eventually the re-painted datagrid.

Thanks

From: amazon otter
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top