 |
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 21st, 2012, 08:25 AM
|
Registered User
|
|
Join Date: Jun 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 13 - Applying the Filter
Hello Imar, my name is Valentine, I am on Chapter 13 and up till now I have tried to find answers on my own for questions that I run into but I can't seem to get the filter to work for me in the Try it Out on Page 450.
The first part works for me, when I bound the sqldatasource1 control to the DropDownList control without applying the WHERE clause, it works fine and displays the data applying the ORDER BY clause.
However, when I add GridView and now follow the instruction to apply the WHERE filter in the same sqldatasource1 control then nothing shows up the in the DropDownList. Only the default text "Make a Selection" show up. There is nothing anymore in the DropDownList.
If I do "Test Query" in the Configure Source Wizard, it works, I get a box to enter the parameter and the result will be displayed. So I was wondering if I am supposed to create two Sqldatasource controls? one for the DropDownList and one for the GridView control?
Thanks for all your amazing responses to other questions.
Valentine
|

August 21st, 2012, 11:24 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Can you post your code? When you paste it here, please paste it in Notepad first to get rid of color coding and then use the Code button (#) to mark the text as code.
Cheers,
Imar
|

August 22nd, 2012, 07:43 AM
|
Registered User
|
|
Join Date: Jun 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar for the Response, I was able to get it to work by creating 2 sqldatasource as you can see from the code below. If that is not how it is suppose to work, please let me know what I should have done differently.
Thanks
Code:
<%@ Page Title="Planet Wrox - Management - Review" Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="Reviews.aspx.cs" Inherits="Management_Reviews" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Name"
DataValueField="Id">
<asp:ListItem Value="">Make a Selection</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Summary" HeaderText="Summary"
SortExpression="Summary" />
<asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
<asp:BoundField DataField="GenreId" HeaderText="GenreId"
SortExpression="GenreId" />
<asp:CheckBoxField DataField="Authorized" HeaderText="Authorized"
SortExpression="Authorized" />
<asp:BoundField DataField="CreateDateTime" HeaderText="CreateDateTime"
SortExpression="CreateDateTime" />
<asp:BoundField DataField="UpdateDateTime" HeaderText="UpdateDateTime"
SortExpression="UpdateDateTime" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
SelectCommand="SELECT * FROM [Review] WHERE ([GenreId] = @GenreId)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="GenreId"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
SelectCommand="SELECT [Id], [Name] FROM [Genre] ORDER BY [SortOrder]">
</asp:SqlDataSource>
</asp:Content>
|

August 22nd, 2012, 07:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
That's how it's supposed to work: one for the genres in the drop-down, the other for the review. Step 2 on page 450 shows you how to add the second one...
Imar
|

August 22nd, 2012, 07:54 AM
|
Registered User
|
|
Join Date: Jun 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok then, thanks again for your response. That answers my question
Have a nice day
Valentine
|
|
 |
|