Referencing Dataset row not Datagrid row

Discussion in 'ASP .Net' started by Craig, Nov 2, 2004.

  1. Craig

    Craig Guest

    How do I reference the dataset row number for the data in the datagrid and
    not the datagrid row itself when calling a function from the HTML?

    When I am calling a function from a datagrid column as shown below I can use
    'Container.ItemIndex' which refers to datagrid row number but I want the row
    number of the dataset. If you implement paging then the row number of the
    first row is the same no matter what page you are on which is not what I
    want.

    In some events I believe it is e.item.itemindex that refers to the row
    number of the dataset but I need to pass it from the HTML.

    <asp:TemplateColumn HeaderText="FYC Potential">
    <ItemTemplate>
    <asp:Label id="Label2" runat="server" Text='<%#
    fDetermineFYC(Container.ItemIndex) %>'>lblFYCPotential</asp:Label>
    </ItemTemplate>
    </asp:TemplateColumn>
    Craig, Nov 2, 2004
    #1
    1. Advertising

  2. Craig

    Karl Seguin Guest

    Someone might have a better suggestion, but you could always add an
    autoincrementing datacolum to your table,

    DataSet ds = getMyDataSet()
    DataColumn dc = new DataColumn("RowId", typeof(System.Int32));
    dc.AutoIncrement = true;
    dc.AutoIncrementSeed = 1;
    dc.AutoIncrementStep = 1;
    ds.Tables[0].Columns.Add(dc);

    And you can then using DataBinder.Eval(Container.DataItem, "RowId")

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Craig" <> wrote in message
    news:...
    > How do I reference the dataset row number for the data in the datagrid and
    > not the datagrid row itself when calling a function from the HTML?
    >
    > When I am calling a function from a datagrid column as shown below I can

    use
    > 'Container.ItemIndex' which refers to datagrid row number but I want the

    row
    > number of the dataset. If you implement paging then the row number of the
    > first row is the same no matter what page you are on which is not what I
    > want.
    >
    > In some events I believe it is e.item.itemindex that refers to the row
    > number of the dataset but I need to pass it from the HTML.
    >
    > <asp:TemplateColumn HeaderText="FYC Potential">
    > <ItemTemplate>
    > <asp:Label id="Label2" runat="server" Text='<%#
    > fDetermineFYC(Container.ItemIndex) %>'>lblFYCPotential</asp:Label>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    >
    Karl Seguin, Nov 2, 2004
    #2
    1. Advertising

  3. Craig, you could also "do the math" (e.g. page #x, y items per page, etc.)

    "Craig" wrote:

    > How do I reference the dataset row number for the data in the datagrid and
    > not the datagrid row itself when calling a function from the HTML?
    >
    > When I am calling a function from a datagrid column as shown below I can use
    > 'Container.ItemIndex' which refers to datagrid row number but I want the row
    > number of the dataset. If you implement paging then the row number of the
    > first row is the same no matter what page you are on which is not what I
    > want.
    >
    > In some events I believe it is e.item.itemindex that refers to the row
    > number of the dataset but I need to pass it from the HTML.
    >
    > <asp:TemplateColumn HeaderText="FYC Potential">
    > <ItemTemplate>
    > <asp:Label id="Label2" runat="server" Text='<%#
    > fDetermineFYC(Container.ItemIndex) %>'>lblFYCPotential</asp:Label>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    >
    >
    =?Utf-8?B?QmlsbCBCb3Jn?=, Nov 2, 2004
    #3
    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. Winshent
    Replies:
    0
    Views:
    500
    Winshent
    Dec 14, 2004
  2. Neil
    Replies:
    1
    Views:
    1,694
  3. =?Utf-8?B?SnVsaWEgQg==?=

    Adding a new row to a datagrid without a dataset

    =?Utf-8?B?SnVsaWEgQg==?=, Oct 9, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    417
    =?Utf-8?B?SnVsaWEgQg==?=
    Oct 9, 2007
  4. IK

    How to find grid's row that matches row in dataset

    IK, Sep 15, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    171
  5. MrMike

    Referencing Datagrid Rows while Datagrid is Sorted

    MrMike, May 20, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    188
    MrMike
    May 23, 2005
Loading...

Share This Page