Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding Listview to multiple Objects ASP.net 3.5

Status
Not open for further replies.

maadhukari

Programmer
Sep 27, 2010
7
US
Hello,
I am using Object as the data source to my Listview and trying to display data in a Hierarchical manner. I am not able to figure out how to bind these objects to my listviews. Below pasted is the code.
I am trying to place Listview inside another listview, inside another listview inorder to display data in a hierarchical manner. Any help is very much appreciated.
???? area below is where i need help.
Thanks in advance
M.


public class AutoElements
{
public class results_dataset
{
public List<Claims_history> claimsHistory { get; set; }
public int count {get; set;}
}
public class Claims_history
{
public List<Claim> claim { get; set; }
}
public class Claim : ClaimType
{
public string first_payment_date { get; set; }

}
}


Code to extract data from XML :


public class ClaimsProcessing
{
public AutoElements.results_dataset GetResultDataset()
{
AutoElements.results_dataset resultdatasets =
(from b in query.Descendants(xmlns + "results_dataset")
select new AutoElements.results_dataset
{
claimsHistory = (from c in query.Descendants(xmlns + "claims_history")
select new
AutoElements.Claims_history
{
claim = (from d in query.Descendants(xmlns + "claim")
select new AutoElements.Claim()
{
first_payment_date = d.Element(xmlns+"fpdate").Value
}
}
}.ToList(),
count = (int) (int)c.Elements(xmlns + "claim").Count()

}
}


<asp:ObjectDataSource ID="ClueAutoElements" runat="server" SelectMethod="GetResultDataset"
TypeName="CLUEAuto.BusinessLogic.ClaimsProcessing"></asp:ObjectDataSource>
<asp:ListView ID="lv" runat="server" DataSourceID="ClueAutoElements" OnSorting="LvSorting" OnSorted="LvSorted">
<ItemTemplate>
<tr id="row" runat="server" class="group">
<th class="first" runat="server">
<img src="_assets/img/plus.png" alt='Group: <%# Eval("claimsHistory") %>' />
</th>
<th colspan="5" runat="server">(<%# Eval("count") %> )</th>
</tr>
????? <asp:ListView ID="lvItems" runat="server" DataSourceID='<%# Eval("?????") %>'>
????? </asp:ListView>
</ItemTemplate></asp:ListView>
 
you wouldn't set the datasourceid, you would set the datasource property. you would then need to bind the data int he listview itembound event (or something like that). google "nested repeaters" or "nested listview" for examples. it's very common.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Hi Jason,
Thank you very much. What I am trying to write in the ???? area is to bind the Claim class to the second Listview. When I supply "claim" to datasource property I get the error message : claim is not a property of result_dataset class, which is true. How can i assign claim class to the second Listview?
Thanks
M
 
bind "claimsHistory" to the datasource then extract the Claim property in the nested listview
Code:
<asp:ObjectDataSource ID="ClueAutoElements" runat="server" SelectMethod="GetResultDataset"
TypeName="CLUEAuto.BusinessLogic.ClaimsProcessing"></asp:ObjectDataSource>
<asp:ListView DataSourceID="ClueAutoElements">
   <ItemTemplate>
      <span><%= Eval("count")%></span>
      <asp:ListView DataSource='<%# Eval("claimsHistory") %>'>
         <ItemTemplate>
            <%= ((Claim)DataItem).first_payment_date%>
         </ItemTemplate>
      </asp:ListView>
   </ItemTemplate>
</asp:ListView>
while this works, it's very ulgy and reverts back to the days of classic asp spaghetti code. it would be cleaner to handle this in the code behind. I will leave that exercise to you.

also you are a slinging the runat attribute around too much. you don't need to apply it to html elements unless you need access to the object on the server. runat ties closely with viewstate. viewstate can kill the performance of a page.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Hi Jason,
Thank you. I get the following error at the below line of code
<%= ((Claim)DataItem).first_payment_date%>

Error is :The type or namespace name 'Claim' could not be found (are you missing a using directive or an assembly reference?)
 
the error tells you what to do. add the namespace to the markup file, or reference the full name of the type. it also looks like Claim is a child class of AutoElements so it would need look like this
Code:
((The.NameSpace.For.AutoElements.Claim)DataItem).AProperty

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thank you Jason,
<%= ((CLUEAuto.BusinessEntities.ClueAutoElements.Claim)DataItem).first_payment_date%>
Now I get "The name 'DataItem' doesnot exist in the current context" error.
 
it's something like that, I don't remember the exact object name. try Container.DataItem. the help files should also be able to provide details.



Jason Meckley
Programmer

faq855-7190
faq732-7259
 
I tried System.ComponentModel.Container but it doesn't have a defeiniton for DataItem.
 
no it wouldn't be that. it would be web specific.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top