How to get DataField value of a cell

Discussion in 'ASP .Net' started by Dinçer, Dec 9, 2004.

  1. Dinçer

    Dinçer Guest

    Hi all!

    I want to get the datafield value of a cell in a datagrid item. How can I do
    this?
    I have a for loop (as below) and I am able to get the data in the cell, but
    not the datafield value.

    Regards.

    foreach(DataGridItem dataGridItem in MyDataGrid)

    {

    string cellText = dataGridItem.Cells[0].Text;

    //string cellValue = ???


    }
     
    Dinçer, Dec 9, 2004
    #1
    1. Advertising

  2. What do you mean by datafield value?

    Eliyahu

    "Dinçer" <dincer"AT"o2.pl> wrote in message
    news:OM1bd%...
    > Hi all!
    >
    > I want to get the datafield value of a cell in a datagrid item. How can I

    do
    > this?
    > I have a for loop (as below) and I am able to get the data in the cell,

    but
    > not the datafield value.
    >
    > Regards.
    >
    > foreach(DataGridItem dataGridItem in MyDataGrid)
    >
    > {
    >
    > string cellText = dataGridItem.Cells[0].Text;
    >
    > //string cellValue = ???
    >
    >
    > }
    >
    >
     
    Eliyahu Goldin, Dec 9, 2004
    #2
    1. Advertising

  3. Dinçer

    Dinçer Guest

    "dataGridItem.Cells[0].Text" gives me the value of the cell; for example :
    Bill
    "dataGridItem.Cells[1].Text" gives me the value of the second cell; for
    example : Gates
    These are OK.

    What I need is the field name of these values in the database; for example:
    "name" and "surname" for the data above

    Is there anyway to get these values?


    "Eliyahu Goldin" <> wrote in message
    news:...
    > What do you mean by datafield value?
    >
    > Eliyahu
    >
    > "Dinçer" <dincer"AT"o2.pl> wrote in message
    > news:OM1bd%...
    > > Hi all!
    > >
    > > I want to get the datafield value of a cell in a datagrid item. How can

    I
    > do
    > > this?
    > > I have a for loop (as below) and I am able to get the data in the cell,

    > but
    > > not the datafield value.
    > >
    > > Regards.
    > >
    > > foreach(DataGridItem dataGridItem in MyDataGrid)
    > >
    > > {
    > >
    > > string cellText = dataGridItem.Cells[0].Text;
    > >
    > > //string cellValue = ???
    > >
    > >
    > > }
    > >
    > >

    >
    >
     
    Dinçer, Dec 9, 2004
    #3
  4. If your column is a BoundColumn, and if it is not autogenerated, you can get
    the field name as

    (myGrid.Columns[0] as BoundColumn).DataField

    If it is autogenerated, you can get the field names in ItemCreated event for
    the grid column headers. The cell text will be set to the column header,
    which should be the same as data field name.

    Eliyahu

    "Dinçer" <dincer"AT"o2.pl> wrote in message
    news:...
    > "dataGridItem.Cells[0].Text" gives me the value of the cell; for example :
    > Bill
    > "dataGridItem.Cells[1].Text" gives me the value of the second cell; for
    > example : Gates
    > These are OK.
    >
    > What I need is the field name of these values in the database; for

    example:
    > "name" and "surname" for the data above
    >
    > Is there anyway to get these values?
    >
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:...
    > > What do you mean by datafield value?
    > >
    > > Eliyahu
    > >
    > > "Dinçer" <dincer"AT"o2.pl> wrote in message
    > > news:OM1bd%...
    > > > Hi all!
    > > >
    > > > I want to get the datafield value of a cell in a datagrid item. How

    can
    > I
    > > do
    > > > this?
    > > > I have a for loop (as below) and I am able to get the data in the

    cell,
    > > but
    > > > not the datafield value.
    > > >
    > > > Regards.
    > > >
    > > > foreach(DataGridItem dataGridItem in MyDataGrid)
    > > >
    > > > {
    > > >
    > > > string cellText = dataGridItem.Cells[0].Text;
    > > >
    > > > //string cellValue = ???
    > > >
    > > >
    > > > }
    > > >
    > > >

    > >
    > >

    >
    >
     
    Eliyahu Goldin, Dec 9, 2004
    #4
    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. richard

    get DataField value in UpdateCommand

    richard, Dec 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    431
    richard
    Dec 2, 2003
  2. Husht

    Get the datafield name??

    Husht, Aug 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    417
    Eliyahu Goldin
    Aug 4, 2004
  3. Husht

    Get the datafield name??

    Husht, Aug 4, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    443
    Husht
    Aug 4, 2004
  4. mianiro

    Get DataField Item of a Column?

    mianiro, Feb 27, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    348
    Eliyahu Goldin
    Feb 27, 2007
  5. Dave

    Using a datafield value as a function argument

    Dave, Dec 1, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    165
Loading...

Share This Page