Click here to Skip to main content
15,893,814 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: ASP.NET - Create a questionnaire/test on the fly. Pin
pmarfleet12-Jan-09 9:18
pmarfleet12-Jan-09 9:18 
GeneralRe: ASP.NET - Create a questionnaire/test on the fly. Pin
SmartSpider12-Jan-09 9:33
SmartSpider12-Jan-09 9:33 
GeneralRe: ASP.NET - Create a questionnaire/test on the fly. Pin
pmarfleet12-Jan-09 9:45
pmarfleet12-Jan-09 9:45 
GeneralRe: ASP.NET - Create a questionnaire/test on the fly. Pin
SmartSpider12-Jan-09 10:25
SmartSpider12-Jan-09 10:25 
GeneralRe: ASP.NET - Create a questionnaire/test on the fly. Pin
pmarfleet12-Jan-09 11:35
pmarfleet12-Jan-09 11:35 
GeneralRe: ASP.NET - Create a questionnaire/test on the fly. Pin
SmartSpider12-Jan-09 17:41
SmartSpider12-Jan-09 17:41 
QuestionRe: ASP.NET - Create a questionnaire/test on the fly. Pin
SmartSpider20-Jan-09 9:13
SmartSpider20-Jan-09 9:13 
AnswerRe: ASP.NET - Create a questionnaire/test on the fly. Pin
pmarfleet20-Jan-09 11:09
pmarfleet20-Jan-09 11:09 
Yes. You can use a data binding expression to do this.

Below I have posted the code for a page that displays a hierarchical list of customers with orders from the sample Northwind database using ADO.NET Entity Framework. I use a databinding expression in the child list control displaying order details to display the customer's country against every order. The databinding expression is a bit clumsy (lots of calls to .Parent) but it works.

ASPX code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListView1" runat="server"
onitemdatabound="ListView1_ItemDataBound">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><%#Eval("CustomerID") %></li>
<asp:ListView ID="ListView2" runat="server">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><%#Eval("OrderID") %>&nbsp;<%#((NorthwindModel.Customers)((ListViewDataItem)Container.Parent.Parent.Parent).DataItem).Country %></li>
</ItemTemplate>
</asp:ListView>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>

Code-behind file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (NorthwindModel.NorthwindEntities context = new NorthwindModel.NorthwindEntities())
{
ListView1.DataSource = from c in context.Customers
orderby c.CustomerID
select c;
ListView1.DataBind();
}
}
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
string customerID = ((NorthwindModel.Customers)((ListViewDataItem)e.Item).DataItem).CustomerID;
ListView listView2 = e.Item.FindControl("ListView2") as ListView;

using (NorthwindModel.NorthwindEntities context = new NorthwindModel.NorthwindEntities())
{
var orders = (from o in context.Orders
where o.Customers.CustomerID == customerID
select o).ToList();

listView2.DataSource = orders;
listView2.DataBind();
}
}
}

Paul Marfleet

"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush


GeneralRe: ASP.NET - Create a questionnaire/test on the fly. Pin
SmartSpider20-Jan-09 11:44
SmartSpider20-Jan-09 11:44 
QuestionFormsAuthentication Failing in IE6 Pin
Robymon12-Jan-09 6:44
Robymon12-Jan-09 6:44 
Questionsession Expire Pin
mohit_p2212-Jan-09 5:49
mohit_p2212-Jan-09 5:49 
AnswerRe: session Expire Pin
Not Active12-Jan-09 5:53
mentorNot Active12-Jan-09 5:53 
AnswerRe: session Expire Pin
Colin Angus Mackay12-Jan-09 11:20
Colin Angus Mackay12-Jan-09 11:20 
QuestionError while exporting PPT 2007 on Windows 2008 using ASP.NET Pin
Jadhav Ajay12-Jan-09 5:02
professionalJadhav Ajay12-Jan-09 5:02 
AnswerRe: Error while exporting PPT 2007 on Windows 2008 using ASP.NET Pin
Paddy Boyd12-Jan-09 5:26
Paddy Boyd12-Jan-09 5:26 
GeneralRe: Error while exporting PPT 2007 on Windows 2008 using ASP.NET Pin
Jadhav Ajay12-Jan-09 5:32
professionalJadhav Ajay12-Jan-09 5:32 
QuestionApp showing inbox for wrong user Pin
marky77712-Jan-09 3:39
marky77712-Jan-09 3:39 
AnswerRe: App showing inbox for wrong user Pin
Abhijit Jana12-Jan-09 3:56
professionalAbhijit Jana12-Jan-09 3:56 
GeneralRe: App showing inbox for wrong user Pin
marky77712-Jan-09 4:03
marky77712-Jan-09 4:03 
AnswerRe: App showing inbox for wrong user Pin
Paddy Boyd12-Jan-09 5:27
Paddy Boyd12-Jan-09 5:27 
QuestionAsp.net with vb.net using wizard control Pin
naseer_8412-Jan-09 1:48
naseer_8412-Jan-09 1:48 
Questionhow to handle validation control manually? Pin
mr_muskurahat12-Jan-09 1:30
mr_muskurahat12-Jan-09 1:30 
AnswerRe: how to handle validation control manually? Pin
Rajdev Ramasamy12-Jan-09 2:39
Rajdev Ramasamy12-Jan-09 2:39 
Questionupdateing web.config Pin
rajkumar.312-Jan-09 1:13
rajkumar.312-Jan-09 1:13 
AnswerRe: updateing web.config Pin
Vimalsoft(Pty) Ltd12-Jan-09 1:19
professionalVimalsoft(Pty) Ltd12-Jan-09 1:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.