 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

August 10th, 2011, 07:08 PM
|
|
Authorized User
|
|
Join Date: Aug 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Data doesn's display
Hi Imar,
I'm doing a very small project. I created a page (Courses) with some clickable courses that are supposed to take you to a ViewDetails page so you can see the details of the chosen subject. For some reason, when I click on the link, it takes me to the ViewPage ( http://localhost:3266/CollegeReg/Vie...ls.aspx?Id=ACG 2001 Principles of Accounting I ) but nothing is display. I got the codes from your book and changed it according to my page. This is what I did in the ViewDetails page:
ViewDetails.aspx<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<h3><asp:Literal ID="Literal1" runat="server" Text='<%# Eval ("Courses") %>'></asp:Literal></h3>
<asp:BulletedList ID="CourseDetail" runat="server" DataSource='<%# Eval("CoursesName")%>' DataTextField="Title"
DisplayMode="Text">
</asp:BulletedList>
</ItemTemplate>
</asp:Repeater>
ViewDetails.aspx.vbProtected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Using myEntities As New CollegeRegEntities()
Dim allCourses = From courses In myEntities.Courses1
Order By courses.CourseName
Select New With {courses.CourseName, courses.CourseSch}
Try Repeater1.DataSource = allCourses
Repeater1.DataBind()
Catch 'I guess some statement to explain the exception what can I put?
End Try
End Using
End Sub
|
|

August 11th, 2011, 04:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You need to take out the Try/Catch statement so you can see the real error. My guess is that it has to do with you data binding. It seems that you're binding the bulleted list to a collection called CoursesName but I don't see you define or select that anywhere.
Can you post questions not directly related to the book (such as this one) in a more general ASP.NET category here: http://p2p.wrox.com/asp-net-4-539/ ? Makes it easier for everyone to find what they are looking for.
Cheers,
Imar
|
|

August 11th, 2011, 04:36 PM
|
|
Authorized User
|
|
Join Date: Aug 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Yes, now I'm getting this error:
The DataSourceID of 'Repeater1' must be the ID of a control of type IDataSource. A control with ID 'EntityDataSource1' could not be found.
Line 13: Repeater1.DataBind()
How can I fix it?
Sorry Imar I'm very new with this
Note: how can I do to pass this to the category it belongs
|
|

August 12th, 2011, 03:23 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Looks like this error came from a differnet source file than the one you posted? I don't see 'EntityDataSource1' defined anywhere.
Cheers,
Imar
|
|

August 12th, 2011, 03:50 PM
|
|
Authorized User
|
|
Join Date: Aug 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
ay Imar, this is really frustrating. :( I changed it in another way, since it didn't work and I'm new with this.
Now I inserted a GridView to my Courses page with the linkable courses which take me to the ViewDetail page, in this ViewDetail page, I inserted a DetalsView. Now, when I click the course name in the Courses page, it takes me to the ViewDetail page, and you can see in the browser the name of the course was changed, however, the ViewDetail page always display the same course name no matter if I had picked another from the Courses page.
Why the ViewDetail page doesn't follow what the courses page is telling?
|
|

August 12th, 2011, 04:09 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I can't say anything useful about that without seeing all the relevant code and a detailed description of what you're doing....
My guess is that yuu're not telling the details page what to display. Apparently, you're doing a redirct and forward the ID of the course to the next page. You need to use that ID in your data source to find the right course and assign it to a Details View.
Cheers,
Imar
|
|

August 12th, 2011, 04:15 PM
|
|
Authorized User
|
|
Join Date: Aug 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
In the Course page I have this:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Semester" DataValueField="Id"
AutoPostBack="True">
<asp:ListItem>Choose a Semester</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource2"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical">
<AlternatingRowStyle BackColor="Gainsboro" />
<Columns>
<asp:BoundField DataField="Category" HeaderText="Category"
SortExpression="Category" />
<asp:HyperLinkField DataNavigateUrlFields="CourseName"
DataNavigateUrlFormatString="ViewDetails.aspx?Id={ 0}"
DataTextField="CourseName" HeaderText="Courses" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
</p>
<p>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:CollegeRegConnectionString1 %>"
SelectCommand="SELECT [CourseName], [Category] FROM [Courses] WHERE ([SemesterId] = @SemesterId)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="SemesterId"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CollegeRegConnectionString1 %>"
SelectCommand="SELECT [Id], [Semester] FROM [Semesters] ORDER BY [Id]">
</asp:SqlDataSource>
</p>
</asp:Content>
In the ViewDetails I have:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
CellPadding="4" DataKeyNames="Id" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None" Height="50px" Width="726px">
<AlternatingRowStyle BackColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<EditRowStyle BackColor="#2461BF" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<Fields>
<asp:BoundField DataField="CourseName" HeaderText="CourseName"
SortExpression="CourseName" />
<asp:BoundField DataField="CourseDesc" HeaderText="CourseDesc"
SortExpression="CourseDesc" />
<asp:BoundField DataField="CourseSch" HeaderText="CourseSch"
SortExpression="CourseSch" />
<asp:BoundField DataField="SeatAvail" HeaderText="SeatAvail"
SortExpression="SeatAvail" />
<asp:BoundField DataField="Semester" HeaderText="Semester"
SortExpression="Semester" />
</Fields>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
</asp:DetailsView>
<h2>Professors teaching this course:</h2>
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Members"
DataValueField="Members" AutoPostBack="True">
</asp:CheckBoxList>
<asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataSourceID="SqlDataSource3" ForeColor="Black"
GridLines="Horizontal" Height="50px" Width="176px">
<EditRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="SeatAvail" HeaderText="SeatAvail"
SortExpression="SeatAvail" />
</Fields>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
</asp:DetailsView>
<br />
<asp:Button ID="Button1" runat="server" Text="Register" />
Note: You have to <a href="Account/Login.aspx?ReturnUrl=">Log In</a> in order to register for courses.
<strong>NEW STUDENTS</strong> have to <a href="Account/Register.aspx?ReturnUrl=">open an account</a> first<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:CollegeRegConnectionString1 %>"
SelectCommand="SELECT Faculty.Members, Courses.CourseName, Courses.SeatAvail FROM Courses INNER JOIN Faculty ON Courses.Id = Faculty.CourseId">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:CollegeRegConnectionString1 %>"
SelectCommand="SELECT [Members], [Id] FROM [Faculty] WHERE ([Id] = @Id)">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CollegeRegConnectionString1 %>"
SelectCommand="SELECT Categories.Category, Courses.CourseName, Courses.CourseDesc, Courses.CourseSch, Courses.SeatAvail, Courses.Id, Faculty.Members, Semesters.Semester FROM Categories INNER JOIN Courses ON Categories.Id = Courses.CategoryId INNER JOIN Faculty ON Categories.Id = Faculty.CategoryId AND Courses.Id = Faculty.CourseId INNER JOIN Semesters ON Courses.SemesterId = Semesters.Id AND Faculty.SemesterId = Semesters.Id"
UpdateCommand="UPDATE Categories SET Category = FROM Categories INNER JOIN Courses ON Categories.Id = Courses.CategoryId INNER JOIN Faculty ON Categories.Id = Faculty.CategoryId AND Courses.Id = Faculty.CourseId INNER JOIN Semesters ON Courses.SemesterId = Semesters.Id AND Faculty.SemesterId = Semesters.Id">
</asp:SqlDataSource>
<br />
</asp:Content>
|
|

August 13th, 2011, 03:36 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You need to set up a Query String WhereParameter on the SqlDataSource on the details page so it filters records that match the Id you're passing in the query string. Pages 447 and further have more information. They show you how to use a ControlParameter but the principle is the same for a QueryStringParameter. In addition you may want to look at page 504 and further.
A few tips for posting code in forums like these:
1. Please use the Code button on the toolbar to wrap your code in code tags.
2. Remove stuff that isn't really needed. All the various *Style elements and presentation settings on the controls (BackColor and so on) make it much more difficult to read your code while they are not needed to demonstrate the problem.
Cheers,
Imar
|
|

August 13th, 2011, 03:26 PM
|
|
Authorized User
|
|
Join Date: Aug 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
OMG! thanks Imar
I finally got it, yes! thanks soooo much
|
|
 |
|