473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Problem with displaying query data in ".aspx" page

126 100+
Hello everyone,

I have been trying to solve this problem from past two days. I am working for my project and stuck with this problem.

Please help me out, your help will be greatly appreciated.

Well, this is what I am trying to do:

1. I have following 3 tables:

Expand|Select|Wrap|Line Numbers
  1. a) Course
  2.    - CourseID, int, autoincrement
  3.    - CourseName, nvarchar(50)
  4.    - WeeksPerCourse, int
  5.    - ClassesPerWeek, int
  6.  
  7. b) Weeks
  8.     - WeekID, int, autoincrement
  9.     - WeekNumber, int
  10.     - CourseID
  11.  
  12. c) ClassTopics
  13.     - ClassTopicID, int, autoincrement
  14.     - ClassNumber, int
  15.     - TopicName, nvarchar(100)
  16.     - WeekID, int
Each course may have multiple weeks and each week may have multiple class topics.

And, now I want to display data from the above mentioned tables as follows in my "Index.aspx" page.

Expand|Select|Wrap|Line Numbers
  1. int weeks = "Select * from Weeks Where CourseID=1" //Say CourseID =1
  2. <table>
  3. //I want to repeat <tr> upto the number of weeks that the CourseID "1" has in Weeks table
  4. <tr>
  5. //I want to repeat <td> upto the number of classes for each week with CourseID "1"  
  6. <td> data </td> //I want to display "TopicName" of each class from "ClassTopics" table in between <td> cell
  7. </tr>
  8. </table>
Please kindly give me an idea on how to implement the above illustrated procedure.

Please let me know if I confused you.

I have tried with repeater control but unable to implement the above mentioned procedure.

Your help will be greatly appreciated. Thanks a million in advance.
Nov 29 '08 #1
3 1667
OuTCasT
374 256MB
Are u using visual studio ??
Dec 2 '08 #2
Frinavale
9,735 Expert Mod 8TB
Have you considered using a GridView to display the data?
Dec 2 '08 #3
JFKJr
126 100+
Thanks for the replies.

I am using Visual Studio 2008 and C# to create/design ".aspx" pages.

After hours of tweaking, I have suceeded in implementing the above mentioned procedure using DataList, GridView and Repeater controls.

But, ran into another problem.

Your help/idea will be greatly appreciated.

Well, this is what I am trying to do:

1. I have following 3 tables:

Expand|Select|Wrap|Line Numbers
  1. a) Weeks 
  2.     - WeekID, int, autoincrement 
  3.     - WeekNumber, int 
  4.     - CourseID 
  5.  
  6. b) CourseMaterials
  7.     - CMFile_ID, int, autoincrement
  8.     - CMFile_UID, uniqueidentifier
  9.     - CMFile_Name1, nvarchar(Max)
  10.     - CMFile_Name2, nvarchar(50)
  11.     - CMFile_Content, image
  12.     - CMContent_Type, nvarchar(50)
  13.     - WeekID, int
  14.  
  15. c) CMLinks
  16.     - CMLink_ID, int, autoincrement
  17.     - CMLink_Name, nvarchar(50)
  18.     - CMLink_URL, nvarchar(Max)
  19.     - WeekID, int
2. "Index.aspx" page

Expand|Select|Wrap|Line Numbers
  1. <asp:DataList ID="CourseDataList" runat="server">
  2. <ItemTemplate>
  3.     <tr>
  4.        <td><%#DataBinder.Eval(Container.DataItem, "WeekNumber")%></td>
  5.        <td>
  6.           <asp:Repeater ID="CMRepeater" runat="server" DataSource='<%#DataBinder.Eval(Container, "DataItem.WeekCMs")%>'>
  7.           <ItemTemplate>
  8.              <li><%#DataBinder.Eval(Container.DataItem, "CMFile_Name2")%></li>
  9.           </ItemTemplate>
  10.           </asp:Repeater>
  11.        </td>
  12.     </tr>
  13. </ItemTemplate>
  14. </asp:DataList>
3. "Index.aspx.cs" Page

Expand|Select|Wrap|Line Numbers
  1. private int courseID=1;
  2. protected void Page_Load(object sender, EventArgs e)
  3. {
  4.    bindData();
  5. }
  6. private void bindData()
  7. {
  8.    SqlConnection con = new SqlConnection();
  9.    con.ConnectionString = "" // Defined my connection string here
  10.    con.Open();
  11.  
  12.    SqlCommand sql1 = new SqlCommand("Select * From Weeks Where CourseID='" + courseID + "'", con);
  13.    sql1.CommandType = CommandType.Text;
  14.    SqlDataAdapter adapter1 = new SqlDataAdapter(sql1);
  15.    adapter1.TableMappings.Add("Table", "Weeks");
  16.    DataSet ds = new DataSet("Weeks");
  17.    adapter1.Fill(ds);
  18.  
  19.    SqlCommand sql2 = new SqlCommand("Select * From CourseMaterials", con);
  20.    sql2.CommandType = CommandType.Text;
  21.    SqlDataAdapter adapter2 = new SqlDataAdapter(sql2);
  22.    adapter2.TableMappings.Add("Table", "CourseMaterials");
  23.    adapter2.Fill(ds);
  24.  
  25.    DataColumn parent = ds.Tables["Weeks"].Columns["WeekID"];
  26.    DataColumn child = ds.Tables["CourseMaterials"].Columns["WeekID"];
  27.    ds.Relations.Add("WeekCMs", parent, child);
  28.  
  29.    CourseDataList.DataSource = ds;
  30.    CourseDataList.DataBind();
  31.  
  32.    con.Close();
  33. }
The above functionality is working perfectly fine. I am able to display each week "WeekNumber" and course materials in a course timeline.

But, I also want to display each week course links from the above "CMLinks" table by including the following line in the above repeater control at line #9 (in "index.aspx" page)
Expand|Select|Wrap|Line Numbers
  1. <li><%#DataBinder.Eval(Container.DataItem, "CMLink_Name")%></li>
Any thoughts/ideas on how to display course links along with course materials for each week in the course timeline?

Please help me out. Thanks a million in advance.
Dec 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: peter | last post by:
Hi, I have 2 questions: 1) I have read the articles on how to embedd and image in a resource file. I have also read the articles on how to open it from the resource file and put it in a...
2
by: Murphy | last post by:
Our website contains subdirectories for each subsidiary company, each company has it's own look and feel to the pages in their subdirectory although they are all part of the main website. The...
7
by: BoltonWolf | last post by:
Hi, I was wondering if someone could give me a bit of advice on achiving something. I have a page with a panel on it. Is it possible to then load content into the panel from a second aspx...
1
by: digitalego | last post by:
Sorry if the title is a little confusing... Here is the problem. I am working with a "default.aspx" page that uses a user control I made: ------------------------------ | default.aspx ...
3
by: Pierre | last post by:
Hello, In an aspx page (mypage.aspx) from a web projet, I would like to get the value of a variable of the projet that is declared as public in a module. The variable can be called from...
2
by: mazdotnet | last post by:
Hi, I have the following code in the code-behind file public string section; section = Request.ToString() and I like to display it in my .aspx page (included .ascx) but it's not working.
9
by: =?Utf-8?B?TWF0dE0=?= | last post by:
Is there a way to display/render an ASP page inside of an ASPX page with ASP ..Net 2.0? I'm not trying to back into frames but I have an application that will allow me to customize complex rendered...
0
by: toddwerts | last post by:
I have an aspx page with some form controls in it. They all work fine except for one thing, the control (list) that is populated based on the selected item in the first control (dropdownlist1) is...
2
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
I have a MasterPage. The MasterPage actually contains the <formtag which is used throughout the site. On just certain pages that use that MasterPage, I need the "enctype" for the <formtag to be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.