Help: PageDataSource, Repeater and Codebehind function...

Discussion in 'ASP .Net' started by =?Utf-8?B?Um95?=, Jan 11, 2005.

  1. I have a problem with displaying data from a repeater where the data has to
    be converted in a function. The repeater with PagedDataSource works fine and
    all data is displayed except the columns where the function is executed.

    sample of html code

    <tr>
    <td width="150">Delprosjekt</td>
    <td><%#getvalue(container.itemindex,"DelProsjekt")%></td>
    </tr>

    sample code behind function

    Public Function getValue(ByVal value As Int32, ByVal strColumn As
    String) As String

    Dim strValue As String
    strValue =
    DsBilder1.Tables("Bilder").Rows(value).Item(strColumn).ToString
    If strValue = "" Then strValue = "&nbsp"
    getValue = strValue
    End Function

    I know this only works on the first page because the itemindex is correct in
    the PagedDataSource and the Dataset. The problem araise in page 2 and up.
    I just dont know how i can read the correct row based on the itemindex
    returned from the binded PagedDataSource.

    Should i read the data from the PagedData or from the Dataset? If so how do
    i read this from the PagedData?

    TIA
    --
    Roy
     
    =?Utf-8?B?Um95?=, Jan 11, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Um95?=

    Karl Seguin Guest

    Re: PageDataSource, Repeater and Codebehind function...

    There are a couple simple posibilities...like get get the # of records per
    page, and the page number and add that to value...so if you have 10 records
    per page and you are on page 2 and value = 2 you want the 12th record ((2 -
    1) * 10) + 2

    ((p - 1) * #) + value

    a solution which is 10x better is to simply pass in the row as a parameter:

    <%# GetValue(Container.DataItem, "DelProsjekt") %>

    public function GetValue(row as DataViewRow, column as String) as string
    dim value = Convert.ToString(row(column))
    ....
    end function


    or something similar....Container.DataItem will be of type DataViewRow only
    when you are binding to a dataset, datatable or dataview.

    Karl

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


    "Roy" <> wrote in message
    news:...
    > I have a problem with displaying data from a repeater where the data has

    to
    > be converted in a function. The repeater with PagedDataSource works fine

    and
    > all data is displayed except the columns where the function is executed.
    >
    > sample of html code
    >
    > <tr>
    > <td width="150">Delprosjekt</td>
    > <td><%#getvalue(container.itemindex,"DelProsjekt")%></td>
    > </tr>
    >
    > sample code behind function
    >
    > Public Function getValue(ByVal value As Int32, ByVal strColumn As
    > String) As String
    >
    > Dim strValue As String
    > strValue =
    > DsBilder1.Tables("Bilder").Rows(value).Item(strColumn).ToString
    > If strValue = "" Then strValue = "&nbsp"
    > getValue = strValue
    > End Function
    >
    > I know this only works on the first page because the itemindex is correct

    in
    > the PagedDataSource and the Dataset. The problem araise in page 2 and up.
    > I just dont know how i can read the correct row based on the itemindex
    > returned from the binded PagedDataSource.
    >
    > Should i read the data from the PagedData or from the Dataset? If so how

    do
    > i read this from the PagedData?
    >
    > TIA
    > --
    > Roy
     
    Karl Seguin, Jan 11, 2005
    #2
    1. Advertising

  3. Re: PageDataSource, Repeater and Codebehind function...

    Thanx.. That worked just great. DataRowView did the trick.

    "Karl Seguin" wrote:

    > There are a couple simple posibilities...like get get the # of records per
    > page, and the page number and add that to value...so if you have 10 records
    > per page and you are on page 2 and value = 2 you want the 12th record ((2 -
    > 1) * 10) + 2
    >
    > ((p - 1) * #) + value
    >
    > a solution which is 10x better is to simply pass in the row as a parameter:
    >
    > <%# GetValue(Container.DataItem, "DelProsjekt") %>
    >
    > public function GetValue(row as DataViewRow, column as String) as string
    > dim value = Convert.ToString(row(column))
    > ....
    > end function
    >
    >
    > or something similar....Container.DataItem will be of type DataViewRow only
    > when you are binding to a dataset, datatable or dataview.
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "Roy" <> wrote in message
    > news:...
    > > I have a problem with displaying data from a repeater where the data has

    > to
    > > be converted in a function. The repeater with PagedDataSource works fine

    > and
    > > all data is displayed except the columns where the function is executed.
    > >
    > > sample of html code
    > >
    > > <tr>
    > > <td width="150">Delprosjekt</td>
    > > <td><%#getvalue(container.itemindex,"DelProsjekt")%></td>
    > > </tr>
    > >
    > > sample code behind function
    > >
    > > Public Function getValue(ByVal value As Int32, ByVal strColumn As
    > > String) As String
    > >
    > > Dim strValue As String
    > > strValue =
    > > DsBilder1.Tables("Bilder").Rows(value).Item(strColumn).ToString
    > > If strValue = "" Then strValue = " "
    > > getValue = strValue
    > > End Function
    > >
    > > I know this only works on the first page because the itemindex is correct

    > in
    > > the PagedDataSource and the Dataset. The problem araise in page 2 and up.
    > > I just dont know how i can read the correct row based on the itemindex
    > > returned from the binded PagedDataSource.
    > >
    > > Should i read the data from the PagedData or from the Dataset? If so how

    > do
    > > i read this from the PagedData?
    > >
    > > TIA
    > > --
    > > Roy

    >
    >
    >
     
    =?Utf-8?B?Um95?=, Jan 11, 2005
    #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. Kent P. Iler
    Replies:
    0
    Views:
    622
    Kent P. Iler
    Mar 7, 2004
  2. Jon
    Replies:
    1
    Views:
    511
    Peter Rilling
    Jan 13, 2005
  3. Replies:
    2
    Views:
    1,054
  4. Kent P. Iler
    Replies:
    0
    Views:
    187
    Kent P. Iler
    Mar 7, 2004
  5. Kent P. Iler
    Replies:
    0
    Views:
    194
    Kent P. Iler
    Mar 7, 2004
Loading...

Share This Page