473,563 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ObjectDataSourc e 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 ObjectDataSourc e from my custom
PropertiesDataT able to PagedDataSource . This is the event handler:

protected void rptPropertyList _ItemDataBound( object sender,
RepeaterItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
// Programmaticall y reference the PropertiesRow instance
bound to this RepeaterItem
MyDataClass.Pro pertiesRow property =
(MyDataClass.Pr opertiesRow)
((System.Data.D ataRowView)e.It em.DataItem).Ro w;

Label AgentBranchLabe l =
(Label)e.Item.F indControl("lbl AgentBranch");

if (property.Agent BranchCode.Trim ().ToLower() == "jamh")
{
AgentBranchLabe l.Text = "custom output";
}
else if (property.Agent BranchCode.Trim ().ToLower() ==
"jamw")
{
AgentBranchLabe l.Text = "other custom output";
}
}
}

Now this returns the error:
---------------------------
Unable to cast object of type 'PropertiesRow' to type
'System.Data.Da taRowView'.
Exception Details: System.InvalidC astException: Unable to cast object
of type 'PropertiesRow' to type 'System.Data.Da taRowView'.

Stack Trace:
[InvalidCastExce ption: Unable to cast object of type 'PropertiesRow'
to type 'System.Data.Da taRowView'.]
search.rptPrope rtyList_ItemDat aBound(Object sender,
RepeaterItemEve ntArgs e) in c:\Work\jamesmi llard\search.as px.cs:69

System.Web.UI.W ebControls.Repe ater.OnItemData Bound(RepeaterI temEventArgs
e) +105
System.Web.UI.W ebControls.Repe ater.CreateItem (Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem) +142
System.Web.UI.W ebControls.Repe ater.CreateCont rolHierarchy(Bo olean
useDataSource) +454
System.Web.UI.W ebControls.Repe ater.OnDataBind ing(EventArgs e) +53
System.Web.UI.W ebControls.Repe ater.DataBind() +72
System.Web.UI.W ebControls.Repe ater.EnsureData Bound() +55
System.Web.UI.W ebControls.Repe ater.OnPreRende r(EventArgs e) +12
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +77
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
+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 7122
On 11 Apr, 11:20, jazz...@mail.co m 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.netd ata 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 ObjectDataSourc e 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 ObjectDataSourc e from my custom
PropertiesDataT able to PagedDataSource . This is the event handler:

protected void rptPropertyList _ItemDataBound( object sender,
RepeaterItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
// Programmaticall y reference the PropertiesRow instance
bound to this RepeaterItem
MyDataClass.Pro pertiesRow property =
(MyDataClass.Pr opertiesRow)
((System.Data.D ataRowView)e.It em.DataItem).Ro w;

Label AgentBranchLabe l =
(Label)e.Item.F indControl("lbl AgentBranch");

if (property.Agent BranchCode.Trim ().ToLower() == "jamh")
{
AgentBranchLabe l.Text = "custom output";
}
else if (property.Agent BranchCode.Trim ().ToLower() ==
"jamw")
{
AgentBranchLabe l.Text = "other custom output";
}
}

}

Now this returns the error:
---------------------------
Unable to cast object of type 'PropertiesRow' to type
'System.Data.Da taRowView'.
Exception Details: System.InvalidC astException: Unable to cast object
of type 'PropertiesRow' to type 'System.Data.Da taRowView'.

Stack Trace:
[InvalidCastExce ption: Unable to cast object of type 'PropertiesRow'
to type 'System.Data.Da taRowView'.]
search.rptPrope rtyList_ItemDat aBound(Object sender,
RepeaterItemEve ntArgs e) in c:\Work\jamesmi llard\search.as px.cs:69

System.Web.UI.W ebControls.Repe ater.OnItemData Bound(RepeaterI temEventArgs
e) +105
System.Web.UI.W ebControls.Repe ater.CreateItem (Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem) +142
System.Web.UI.W ebControls.Repe ater.CreateCont rolHierarchy(Bo olean
useDataSource) +454
System.Web.UI.W ebControls.Repe ater.OnDataBind ing(EventArgs e) +53
System.Web.UI.W ebControls.Repe ater.DataBind() +72
System.Web.UI.W ebControls.Repe ater.EnsureData Bound() +55
System.Web.UI.W ebControls.Repe ater.OnPreRende r(EventArgs e) +12
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +77
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
+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.Pro pertiesRow property = (MyDataClass.Pr opertiesRow)
((System.Data.D ataRowView)e.It em.DataItem).Ro w;

To:
MyDataClass.Pro pertiesRow property =
(MyDataClass.Pr opertiesRow)e.I tem.DataItem;

Apr 11 '07 #2

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

Similar topics

2
3427
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 possible with a Typed Dataset ? If so, a code snippet or link to relevant website would be much appreciated.
0
1084
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 System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here 'Dim partoftown = Session("partoftown") ' Dim partoftown =...
0
1441
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 following is the error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Description: An...
1
6401
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 binding it to a repeater control. This repeater control has multiple text boxes and buttons. Can you please tell me how can i do paging in this case ?...
3
2913
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 -- */ OdbcConnection connection = new OdbcConnection("DSN=Whatever"); connection.Open(); string query = "SELECT * FROM ProjectTable";
1
2245
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 triggered so I have to get the values from the database again. Correct? Or is there a way of hiding the row ID’s in the page?
3
9160
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 really had any success. I'm pretty sure I should be casting my XPathSelect() call to something so I can get at its attributes. This seems like it...
1
1799
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 page or is .Net smart enough to use the same dataset from the first request? I researched a bit and found how to cache a dataset, which would be...
0
2543
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 link (1,2,3 so on). The code can be found in SubscriptionCart.aspx.cs. Default.aspx ------------
0
7659
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7580
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.