Prior to adding paging using PagedDataSource I had dropdownlist and search box filters for my DataList. The guts of the code in aspx page for those parameters is below: - <asp:SqlDataSource ID="SqlDataSource1" runat="server"
-
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
-
SelectCommand="SELECT [ProductCode], [ImgUrl], [ImageField], [Featuring], [ProdCategoryID], [Title] FROM [TableSG1] WHERE (([ProdCategoryID] = @ProdCategoryID) AND ([Featuring] LIKE '%' + @Featuring + '%')) ORDER BY [Featuring]">
-
-
<SelectParameters>
-
<asp:ControlParameter ControlID="DropDownList1" Name="ProdCategoryID"
-
PropertyName="SelectedValue" Type="String" />
-
-
<asp:ControlParameter ControlID="TextBox1" Name="Featuring" PropertyName="Text"
-
Type="String" />
-
When creating the pager using PagedDataSource I did a tutorial which did not have parameters and all the code went in the code behind page. The guts of it is below: - private void BindGrid()
-
{
-
string sql = "SELECT [ProductCode], [ImgUrl], [Featuring], [Title] FROM [TableSG1] DESC";
-
SqlDataAdapter da = new SqlDataAdapter(sql, "Data Source=tcp:s02.winhost.com;Initial Catalog=DB_5890_maindb1;User ID=DB_5890_maindb1_user;Password=xxxxx;Integrated Security=False;");
-
DataTable dt = new DataTable();
-
da.Fill(dt);
-
-
pds.DataSource = dt.DefaultView;
-
pds.AllowPaging = true;
-
pds.PageSize = Convert.ToInt16(ddlPageSize.SelectedValue);
-
pds.CurrentPageIndex = CurrentPage;
-
lnkbtnNext.Enabled = !pds.IsLastPage;
-
lnkbtnPrevious.Enabled = !pds.IsFirstPage;
-
-
DataList1.DataSource = pds;
-
DataList1.DataBind();
-
-
doPaging();
-
}
The pager is great but now I need to add my filters. The page wont load if I add the "SelectParameters" code (above) to my aspx page and if I simply add the "WHERE" clause to the "SELECT" clause in the code behind I get an error stating that I need to add a scalar variable.
I have found some examples through googling but nothing specific enough.
I need assistance if anyone would be kind enough to help.
5 4059
You have posted your question in the asp (Classic ASP) section rather than the asp.net forum section.
I have moved it across for you.
CroCrew~
I'm not sure why you're having problems with the where clause.
What is the error message exactly?
Hi Frinavale,
The error message is "must declare scaler variable @ProdCategoryID"
I have made some progress in getting as far as the following: NB I have shortened the SELECT clause to include only one parameter. - string ddl = DropDownList1.SelectedItem.Value;
-
SqlConnection conn = new SqlConnection("Data Source=tcp:s02.winhost.com;Initial Catalog=DB_5890_maindb1;User ID=DB_5890_maindb1_user;Password=bootsie23000;Integrated Security=False;");
-
-
SqlCommand cmd = new SqlCommand ("SELECT [ProductCode], [ImgUrl], [Featuring], [Title] FROM [TableSG1] WHERE [ProdCategoryID] = @ProdCategoryID");
-
SqlDataAdapter da = new SqlDataAdapter ("SELECT [ProductCode], [ImgUrl], [Featuring], [Title] FROM [TableSG1] WHERE ([ProdCategoryID] = @ProdCategoryID", conn );
-
cmd.Parameters.AddWithValue("@ProdCategoryID", "ddl");
-
DataTable dt = new DataTable();
-
da.Fill(dt);
ProdCategoryID is the name of drop down list as seen in the aspx page control parameter code as follows: - <SelectParameters>
-
<asp:ControlParameter ControlID="DropDownList1" Name="ProdCategoryID"
-
PropertyName="SelectedValue" Type="String" />
DropDownList1 is unbound - code from aspx page is below : - <asp:DropDownList ID="DropDownList1" runat="server"
-
Height="28px" Width="176px" Font-Bold="True"
-
Font-Size="Medium" AutoPostBack="True">
-
<asp:ListItem>Giant Posters</asp:ListItem>
-
<asp:ListItem>Extra Long Posters</asp:ListItem>
-
<asp:ListItem>Regular Posters</asp:ListItem>
-
<asp:ListItem>Slim Posters</asp:ListItem>
-
<asp:ListItem>Small Posters</asp:ListItem>
-
<asp:ListItem>Lenticular Posters</asp:ListItem>
-
<asp:ListItem>Stickers</asp:ListItem>
-
<asp:ListItem>Key Rings</asp:ListItem>
-
<asp:ListItem>Calendars</asp:ListItem>
-
</asp:DropDownList>
I have probably got a bit to far ahead of myself for a newbie. The filter worked when using VWD 2008 Express wysiwag without the pager. But in following the pager tutorial I stuck with its format which did not include a WHERE clause in the SELECT clause. I was hoping to workout how to add them back in afterwards and that is where I am. The pager tutorial took me away from my VB training ( which I am only a beginner of ) and into C#. I have been googling like mad for advice on scalar variables and thought I had done it with the "string ddl = DropDownList1.SelectedItem.Value;" but I am still getting the same error.
Any help is very much appreciated.
- SqlConnection conn = new SqlConnection("Data Source=tcp:s02.winhost.com;Initial Catalog=DB_5890_maindb1;User ID=DB_5890_maindb1_user;Password=bootsie23000;Integrated Security=False;");
-
SqlCommand cmd = new SqlCommand("SELECT [ProductCode], [ImgUrl], [Featuring], [Title] FROM [TableSG1] WHERE [ProdCategoryID] = @ProdCategoryID ORDER BY [Featuring]", conn);
-
-
SqlParameter param = new SqlParameter();
-
param.ParameterName = "@ProdCategoryID";
-
-
param.Value = DropDownList1.SelectedItem.Value;
-
cmd.Parameters.Add(param);
-
-
SqlDataAdapter da = new SqlDataAdapter(cmd);
-
DataTable dt = new DataTable();
-
da.Fill(dt);
Hmm interesting.
I've never used the AddWithValue method before.
I was about to recommend that you use the add method instead but it looks like you figured it out before I got the chance.
Thanks for sharing your solution!
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Umut K. |
last post by:
Hi all,
I've a DataList control and it's DataBound by a SqlDataReader...
The Reader returns say 3 records and as expected the datalist shows 3 rows.
What i want to do is to add another extra...
|
by: V. Jenks |
last post by:
What seems like a simple thing is apparently not so
straightforward?
I have a datalist.
Inside of that datalist is an <itemtemplate> secion which
contains other server controls such as a...
|
by: wh1974 |
last post by:
I have a DataTable that I'm binding to a DataList control on my web page. I
want to be able to restrict the number of rows that are initially displayed
from the DataTable. For example I want to be...
|
by: Bharat |
last post by:
Hi Folks,
Suppose I have two link button on a page (say lnkBtn1 and
lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically
created control. And On the click event of the lnkBtn2 I...
|
by: Miguel Dias Moura |
last post by:
Hello,
I created a datalist in an ASP.Net / VB page.
I display the image and price of a few products.
When a user clicks an image I want to load the page
"detail.aspx?number=id" and send the...
|
by: Mike |
last post by:
Hi!
Been stuck on this one for a bit. Would really appreciate any help on
this one.
To start. I have a sql database table with the following data and
design (ex)
...
|
by: Patrick.O.Ige |
last post by:
I'm trying to page a Datalist below using VS.NET
But i get the error:-
System.NullReferenceException: Object reference not set to an instance of an
object.
At line:- btnPrev.Visible = (Not...
|
by: David |
last post by:
Hello.
How can I enable and manage paging capability on DataList control like
DataGrid?
Thank you.
|
by: kapamaroy |
last post by:
Hi,
I am working on a website and I have to reperesent the contents of a List<> in several pages. I use a PagedDataSource item and a DataList control for that. What I want to do is to create a links...
|
by: sureshl |
last post by:
The below workss very fine , in the type for previous, next concept for paging,
i need to do with page number Like this,
1 2 3 4......23 (http://bytes.com/topic/visual-basic-net/) Like this...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |