|
The easiest way to approach this would be to use a data-bound control like a ListView to display the questions and corresponding input controls. Within the ItemTemplate for your data-bound control, you can declare an instance of each type of input control you want to use (TextBox, CheckBox etc.) Then at run-time, override the ItemDataBound event for your control and show/hide each input control for the current question being rendered as appropriate. On postback, to save the user's input, loop through the Items collection for the control, use FindControl to locate the correct control containing the user's input, then save the information to your database (or whatever)
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Paul,
Appreciate your response - it reinforces the fact that I am a newbie (but I'll get there) . I am going to read in detail on the ListView to see how and if I can use it in my case. I need to present a beautiful looking form, with (dynamic number of) categories, each having (dynamic number of) questions and each question needs to have an appropriate (let's say its only text box for now) control against it. And yes, on postback, I need to go through each answer and save it in a DB. The form needs to look beautiful and organized in catgories with a layout something like
-------------
Category One |
-------------
--> Question 1. In context of gravitational force, what is the difference between 'g' and 'G'?
Answer 1. [Text Box]
--> Question 2. What is the formula for the gravitational pull between two bodies of mass M1 & M2 that are x distance apart?
--> Answer 2. [Text Box]
-------------
Category Two |
-------------
--> Question 1. In context of gravitational force, what is the difference between 'g' and 'G'?
Answer 1. [Text Box]
--> Question 2. What is the formula for the gravitational pull between two bodies of mass M1 & M2 that are x distance apart?
--> Answer 2. [Text Box]
Will the ListView allow for the tables (that's how I am grouping categories and ques within), images, etc?
Thanks,
|
|
|
|
|
To display a list of questions grouped by category you would need 2 ListView controls, one nested inside the ItemTemplate of the other.
Have a look at this[^] open-source ASP.NET Questionnaire application. I've used it in the past as a building-block for creating a survey website.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I was unable to download the sample from the link you pointed me to, but I read a little about ListView control at another website and so far it looks promising. In the sample I read, they had used and asp:AccessDataSource in the aspx file itself and simply pointed to the mdb file with a SELECT query. In my case, I need to select categories from table 1, loop over categories and select questions for each. Not sure how to do this...
Paul - please know, your help and time are much appreciated
Many thanks,
~R
|
|
|
|
|
Bind your parent ListView control that is displaying the categories to a SELECT query that fetches these categories.
Handle the ItemDataBound[^] event for your parent ListView control. This will fire each time data for an individual category is bound to the list control.
The following code demonstrates how to handle this event and use LINQ to get all orders for the child list control associated with a customer from the parent list control. It uses data from the Northwind database. The parent list control is bound to a SqlDataSource control.
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
string customerID = ((System.Data.DataRowView)((ListViewDataItem)e.Item).DataItem)["CustomerID"].ToString();
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
|
|
|
|
|
Paul,
Cannot thank you enough... but Thanks!
~R
|
|
|
|
|
Hi Paul,
I would have posted this as a separate question, but then I would have needed to explain what I am doing and how I am binding the nested ListViews... so I thought I'd try sending my question to you and hope for an answer.
So I have nested ListViews - the parent displays the categories, and in the ItemTemplate of this parent, I have another ListView that displays the questions under that category - now is there a way for me to get the category name bound to parent listview, in the child listview? I can achieve this by modifying my SQL and populate the data source of the child lv with category name as well, but I don't think that's the right way (unecessarily retrieving the category name again, when, it is already available).
Note - the category name is not available in any control of parent lv - it is just displayed using <%#Eval%> within a <th>
Appreciate your help - hope I am not pushing it.
~R
|
|
|
|
|
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") %> <%#((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
|
|
|
|
|
Aha! The Container.Parent - thanks a lot Paul. I did find a workaround, but this is definitely looks sleeker.
My workaround:
In the ItemDataBound of parent lv, where I bind the child lv's data, I modified my SQL - I now first retrieve the category name using:
string catgName = ((System.Data.DataRowView)((ListViewDataItem)e.Item).DataItem)["quesCatgName"].ToString();
Then set my SQL to:
sqlStr = "SELECT quesId, quesText, quesHint, '" + catgName + "' as quesCatgName FROM....."
This way, the category is available as 'quesCatgName' in the child lv - dunno if this causes a greater overhead - I will modify my code to use the approach you sent.
Thanks,
~R
|
|
|
|
|
when trying to login from Logon page it is loging and going to master page and in the Master page different hyperlinks, when i click on any link it is redirected to Logon page.
Login Page btnlogin click code
if (DatabaseLayer.AdminDAO.UserExists(txtUserName.Text, txtPassword.Text))
{
FormsAuthentication.SetAuthCookie(txtUserName.Text, false);
Server.Transfer("~/Admin/Presentation Layer/MainPage.aspx");
}
else
{
Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "msgbox", "alert('Sorry ! Your Login Failed');", true);
}
}
Web.config Code
<authentication mode="Forms">
<forms name="appNameAuth" path="./Admin/" loginurl="./Admin/Admin.aspx" protection="All" timeout="30">
<authorization>
<deny users="?" >
<authorization>
Main Page One Hyper Link
<asp:hyperlink id="HyperLink15" runat="server" navigateurl="~/Admin/Presentation Layer/News.aspx" xmlns:asp="#unknown">News
While clicking any of the Hyper Links it is redirecting to Logon Page.
|
|
|
|
|
in my web application my session got expire while working,
i have specified timeout 20
plz help me to solve this problem
|
|
|
|
|
mohit_p22 wrote: plz help me to solve this problem
What problem? Please restate in the form of a question.
only two letters away from being an asset
|
|
|
|
|
mohit_p22 wrote: in my web application my session got expire while working,
i have specified timeout 20
plz help me to solve this problem
I don't see what the problem is.
Is it that the session expired early? Did you not get a session at all? Is it something else?
|
|
|
|
|
Hi,
I have developed a web application which opens the PPT 2007 using asp.net 3.5. With Office 2003 on Windows XP it works fine, but when installed on Windows 2008 Server which has .Net3.5 and Office 2007 gives the following error:
Error:
Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80080005.
StackTrace:
Server Error in '/VemoWeb' Application.
--------------------------------------------------------------------------------
Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80080005.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80080005.
Source Error: Line 141:Line 142:
Line 143: PowerPoint.Application powerPoint = new PowerPoint.Application();
Line 144: PowerPoint.Presentation ppt = powerPoint.Presentations.Add(MsoTriState.msoTrue);
Line 145:
Source File: c:\inetpub\wwwroot\VemoWeb\App_Code\PPTChart.cs Line: 143
Stack Trace:
[COMException (0x80080005): Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80080005.]
Dundas.Charting.Utilities.ChartPPTExport.CreatePPT(String chartImageFileName, String pptOutputFile) in c:\inetpub\wwwroot\VemoWeb\App_Code\PPTChart.cs:143
[ChartPPTExportException: ChartPPTExportException: Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80080005.]
Dundas.Charting.Utilities.ChartPPTExport.CreatePPT(String chartImageFileName, String pptOutputFile) in c:\inetpub\wwwroot\VemoWeb\App_Code\PPTChart.cs:208
UserControls_Export.imgPPT_Click(Object sender, ImageClickEventArgs e) in c:\inetpub\wwwroot\VemoWeb\UserControls\Export.ascx.cs:142
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +108
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +118
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
Can any one please help me out to resolve this error?
Thanks in advance.
Ajay Jadhav
|
|
|
|
|
I'm going to hazard a guess that powerpoint is not installed on the server.
|
|
|
|
|
Hi Paddy,
Thank you for your response.
I just checked on the Server, but PowerPoint 2007 is installed there.
Looks like something related to permissions, but I am not sure what the solution is.
-----
Ajay Jadhav
http://www.divinet.co.in
|
|
|
|
|
Hi all.
We have an asp.net web email app. Intermittently when a user logs in, it shows the inbox for another user. After you refresh or login and logout, it show the correct inbox.
Has anyone ever experienced something like this? What could possibly be the cause? Went through the code, etc and everything seems fine. Perhaps the server setup?
Any help would be greatly appreciated.
Thanks
M
|
|
|
|
|
marky777 wrote: Intermittently when a user logs in, it shows the inbox for another user.
I think it can be cause of Session Variable, May be previous user session didn't clear properly .
|
|
|
|
|
Yes I get you, we ruled this out as a possibility though.
It's a mystery to us
|
|
|
|
|
You haven't told us what login mechanism you are using.
|
|
|
|
|
Hi,
In my project I used Wizard control,in tht i heve 3 steps
1)EmpPersonal
2) EmpEducation
3) EmpSalary(setup type=finish)
I created 3 diff tables for 3 diff above steps
in EmpPersonal step EmpID automatically gnerate , i set the property in sqlserver IdentityIndex=true,auto icement by 1.
Iam not given the Empid from the design part.It is automaticlly incremented.
when i click finish button all the field values of 3 steps stored in database table.
bt in EmpEducation and Empsalary tables contains EmpId.
wht i want to is when i fill the EmpPersonal page ,when i click next button in wizradcontrol ,how i can get the default generated empid from empPersonal page and tht Empid display in a label in the EmpEducation page ans alsoEmpSalary page before click the next page.
plse give the solution as early as possible.
|
|
|
|
|
i have two button on page on save button causevalidation is true
and on refresh causevalidation is false first i press save
requiredfield validator gets active and my reuirement is on refresh is must disappear.
how is it possible please guide.
umerumerumer
|
|
|
|
|
Please clear the validationsummary control on refresh
Regards,
Rajdev KR
|
|
|
|
|
hello,
can any one help me in writing code to update web.config when installing web application.
need to update when installation wizard is running .. (datasourse, userid,password)...
|
|
|
|
|
What do you mean saying Update webconfig. Explain in detail what do you want to achieve and what are your Challenges
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswam@its.co.za
|
|
|
|