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