Accessing the value of a cell in a datagrid

Discussion in 'ASP .Net Datagrid Control' started by amazon otter via .NET 247, Apr 17, 2004.

  1. 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

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>0VIjK+hQ/Ue0cfG0+RIohQ==</Id>
    amazon otter via .NET 247, Apr 17, 2004
    #1
    1. Advertising

  2. amazon otter via .NET 247

    Prodip Saha Guest

    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
    "amazon otter via .NET 247" <> wrote in message
    news:...
    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

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>0VIjK+hQ/Ue0cfG0+RIohQ==</Id>
    Prodip Saha, Apr 19, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam

    accessing datagrid cell

    Sam, Apr 2, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,237
  2. news.rcn.com
    Replies:
    1
    Views:
    9,631
    Chris Smith
    Jul 12, 2004
  3. chris
    Replies:
    2
    Views:
    553
    Eliyahu Goldin
    Jun 26, 2008
  4. Empire City
    Replies:
    3
    Views:
    390
    Empire City
    Apr 30, 2004
  5. RJ
    Replies:
    1
    Views:
    231
    Eliyahu Goldin
    Feb 17, 2005
Loading...

Share This Page