Welcome to WebmasterWorld Guest from 18.207.136.184

Forum Moderators: open

Message Too Old, No Replies

Using a queryString parameter

Variable not Declared

     
3:20 pm on Jun 11, 2009 (gmt 0)

New User

10+ Year Member

joined:June 11, 2009
posts: 1
votes: 0


I am having an issue using the passed variable for the state;

Here is the passing URL: //localhost/GridViewQueryString_vb.aspx?state=IN

The receiving page will not pick up the value for "state" and gives an undeclared variable "@state" error.

Any help would be appreciated...
<%@ Page Language="VB" %>
<html>
<head runat="server">
<title>Filtering Data In A GridView Using a QueryString</title>
</head>
<body>
<form id="form1" runat="server">

<asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" Runat="server"
DataSourceID="SqlDataSource1" AutoGenerateEditButton="True" DataKeyNames="au_id"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField ReadOnly="true" HeaderText="ID" DataField="au_id" SortExpression="au_id" />
<asp:BoundField HeaderText="Last Name" DataField="au_lname" SortExpression="au_lname" />
<asp:BoundField HeaderText="First Name" DataField="au_fname" SortExpression="au_fname" />
<asp:BoundField HeaderText="Phone" DataField="phone" SortExpression="phone" />
<asp:BoundField HeaderText="Address" DataField="address" SortExpression="address" />
<asp:BoundField HeaderText="City" DataField="city" SortExpression="city" />
<asp:BoundField HeaderText="State" DataField="state" SortExpression="state" />
<asp:BoundField HeaderText="Zip Code" DataField="zip" SortExpression="zip" />
<asp:CheckBoxField HeaderText="Contract" SortExpression="contract" DataField="contract" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" Runat="server" SelectCommand="SELECT [au_id], [au_lname], [au_fname], [phone], [address], [city], [state], [zip], [contract] FROM [authors] WHERE [state] = @state"
UpdateCommand="UPDATE [authors] SET [au_lname] = @au_lname, [au_fname] = @au_fname, [phone] = @phone, [address] = @address, [city] = @city, [state] = @state, [zip] = @zip, [contract] = @contract WHERE [au_id] = @au_id"
ConnectionString="<%$ ConnectionStrings:Pubs %>">
<SelectParameters>
<asp:QueryStringParameter Name="state" QueryStringField="state" DefaultValue="CA" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="au_lname" />
<asp:Parameter Name="au_fname" />
<asp:Parameter Name="phone" />
<asp:Parameter Name="address" />
<asp:Parameter Name="city" />
<asp:Parameter Name="state" />
<asp:Parameter Name="zip" />
<asp:Parameter Name="contract" />
<asp:Parameter Name="au_id" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

3:54 pm on June 11, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 25, 2004
posts:161
votes: 0


i dont do asp, but..
i sat and read your code and the first time state is mentioned is in your select statement.

in php, i would grab the url paramater and put it in a variable.

$state = $_GET['state']; (or something, trying to remember)

it looks like you have refered to @state but at no point have you said that @state = the url value (GET value)
dunno how you do that in asp, but im sure thats what the problem is. hope this helps :-)

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members