473,320 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using PagedDataSource with a Repeater

Hi there,

I'm fairly new to programming with Asp.Net 2.0 so I'm finding myself
regularly fumbling around in the dark a bit, so to speak.

I'm currently using Visual Web Developer and have been following the
www.asp.net data access tutorials to create a DAL and BLL to connect
my web site (a simple real estate property search web site) to my
database (Sql Express 2005).

For my search page I'm using a Repeater to display the search results,
which is bound to an ObjectDataSource that gets the data using a
SelectMethod in my custom BLL class (which calls a stored procedure,
passing through the select parameters). Things have been going fairly
smoothly until I needed to implement paging with the repeater. That in
itself is not the problem as there was a tutorial for that. My problem
is this:

I've created an event handler method for the ItemDataBound event on my
Repeater. With each item (and alternating item) I manipulate certain
fields from my data source for customised display. It was all working
fine until I implemented PagedDataSource - which changes the
datasource returned to the ObjectDataSource from my custom
PropertiesDataTable to PagedDataSource. This is the event handler:

protected void rptPropertyList_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
// Programmatically reference the PropertiesRow instance
bound to this RepeaterItem
MyDataClass.PropertiesRow property =
(MyDataClass.PropertiesRow)
((System.Data.DataRowView)e.Item.DataItem).Row;

Label AgentBranchLabel =
(Label)e.Item.FindControl("lblAgentBranch");

if (property.AgentBranchCode.Trim().ToLower() == "jamh")
{
AgentBranchLabel.Text = "custom output";
}
else if (property.AgentBranchCode.Trim().ToLower() ==
"jamw")
{
AgentBranchLabel.Text = "other custom output";
}
}
}

Now this returns the error:
---------------------------
Unable to cast object of type 'PropertiesRow' to type
'System.Data.DataRowView'.
Exception Details: System.InvalidCastException: Unable to cast object
of type 'PropertiesRow' to type 'System.Data.DataRowView'.

Stack Trace:
[InvalidCastException: Unable to cast object of type 'PropertiesRow'
to type 'System.Data.DataRowView'.]
search.rptPropertyList_ItemDataBound(Object sender,
RepeaterItemEventArgs e) in c:\Work\jamesmillard\search.aspx.cs:69

System.Web.UI.WebControls.Repeater.OnItemDataBound (RepeaterItemEventArgs
e) +105
System.Web.UI.WebControls.Repeater.CreateItem(Int3 2 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem) +142
System.Web.UI.WebControls.Repeater.CreateControlHi erarchy(Boolean
useDataSource) +454
System.Web.UI.WebControls.Repeater.OnDataBinding(E ventArgs e) +53
System.Web.UI.WebControls.Repeater.DataBind() +72
System.Web.UI.WebControls.Repeater.EnsureDataBound () +55
System.Web.UI.WebControls.Repeater.OnPreRender(Eve ntArgs e) +12
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1360
---------------------------

I'm not sure what I need to do in order to access these fields for
each row in my ItemDataBound event handler. I'm a bit lost at the
moment, and I can't seem to find any article that talks about this, so
any help would be greatly appreciated!!!

Cheers,
Karen

Apr 11 '07 #1
1 7108
On 11 Apr, 11:20, jazz...@mail.com wrote:
Hi there,

I'm fairly new to programming with Asp.Net 2.0 so I'm finding myself
regularly fumbling around in the dark a bit, so to speak.

I'm currently using Visual Web Developer and have been following thewww.asp.netdata access tutorials to create a DAL and BLL to connect
my web site (a simple real estate property search web site) to my
database (Sql Express 2005).

For my search page I'm using a Repeater to display the search results,
which is bound to an ObjectDataSource that gets the data using a
SelectMethod in my custom BLL class (which calls a stored procedure,
passing through the select parameters). Things have been going fairly
smoothly until I needed to implement paging with the repeater. That in
itself is not the problem as there was a tutorial for that. My problem
is this:

I've created an event handler method for the ItemDataBound event on my
Repeater. With each item (and alternating item) I manipulate certain
fields from my data source for customised display. It was all working
fine until I implemented PagedDataSource - which changes the
datasource returned to the ObjectDataSource from my custom
PropertiesDataTable to PagedDataSource. This is the event handler:

protected void rptPropertyList_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
// Programmatically reference the PropertiesRow instance
bound to this RepeaterItem
MyDataClass.PropertiesRow property =
(MyDataClass.PropertiesRow)
((System.Data.DataRowView)e.Item.DataItem).Row;

Label AgentBranchLabel =
(Label)e.Item.FindControl("lblAgentBranch");

if (property.AgentBranchCode.Trim().ToLower() == "jamh")
{
AgentBranchLabel.Text = "custom output";
}
else if (property.AgentBranchCode.Trim().ToLower() ==
"jamw")
{
AgentBranchLabel.Text = "other custom output";
}
}

}

Now this returns the error:
---------------------------
Unable to cast object of type 'PropertiesRow' to type
'System.Data.DataRowView'.
Exception Details: System.InvalidCastException: Unable to cast object
of type 'PropertiesRow' to type 'System.Data.DataRowView'.

Stack Trace:
[InvalidCastException: Unable to cast object of type 'PropertiesRow'
to type 'System.Data.DataRowView'.]
search.rptPropertyList_ItemDataBound(Object sender,
RepeaterItemEventArgs e) in c:\Work\jamesmillard\search.aspx.cs:69

System.Web.UI.WebControls.Repeater.OnItemDataBound (RepeaterItemEventArgs
e) +105
System.Web.UI.WebControls.Repeater.CreateItem(Int3 2 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem) +142
System.Web.UI.WebControls.Repeater.CreateControlHi erarchy(Boolean
useDataSource) +454
System.Web.UI.WebControls.Repeater.OnDataBinding(E ventArgs e) +53
System.Web.UI.WebControls.Repeater.DataBind() +72
System.Web.UI.WebControls.Repeater.EnsureDataBound () +55
System.Web.UI.WebControls.Repeater.OnPreRender(Eve ntArgs e) +12
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1360
---------------------------

I'm not sure what I need to do in order to access these fields for
each row in my ItemDataBound event handler. I'm a bit lost at the
moment, and I can't seem to find any article that talks about this, so
any help would be greatly appreciated!!!

Cheers,
Karen
Don't worry I've found the solution to my problem. :)

I changed:
MyDataClass.PropertiesRow property = (MyDataClass.PropertiesRow)
((System.Data.DataRowView)e.Item.DataItem).Row;

To:
MyDataClass.PropertiesRow property =
(MyDataClass.PropertiesRow)e.Item.DataItem;

Apr 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fresh Air Rider | last post by:
Hi There are plenty of examples on the internet of using the PagedDataSource in conjunction with a dataset to implement paging within the Repeater control. Does anyone know if this is...
0
by: dinesh | last post by:
Trying to page results from a repeater. The resulting hyperlinks point o empty references when the page is run. No errors show up Private Sub Page_Load(ByVal sender As System.Object, ByVal e As...
0
by: wrytat | last post by:
I declare a PagedDataSource and make its data source be a arraylist that contains objects that I've created myself. Then I bind a Repeater with this PagedDataSource and an error occurs. The...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
3
by: Franz | last post by:
Hi, If my ProjectTable contains a lot of rows, each time I call the following code, will all the rows be fetched? Or only those 5 records for that page are fetched only? /* -- code start --...
1
by: Fred Dag | last post by:
I want to get the database table ID of a row in a Repeater that uses a PagedDataSource when OnTexctChanged event is fired. It seems that the DataSource property isn’t persisted when the event is...
3
by: Brian | last post by:
Using external XML, I'm trying to build a quiz, but I can't seem to specify the DataSource for the RadioButtonList within a Repeater ItemTemplate. I've tried a number of approaches, but I haven't...
1
by: David Lozzi | last post by:
Howdy, Using .Net 2.0 I am using the PagedDataSource to page through my XML data source. My question and / or problem is is this opening the XML data source every time a user clicks through a...
0
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.