Help: PageDataSource, Repeater and Codebehind function...

G

Guest

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
 
K

Karl Seguin

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
 

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