Hi, I’m writing a web app for the company I work for in asp.net 2.0. I’ve got a GridView and I’ve defined a SqlDataSource to populate it. My problem is I need to use the querystring value to determine which column of data I’m going to display.
If I hardcode the value into the Select command it works fine, but if I try to use Request.QueryString[“id”] in the select command I get a runtime error. I’d say its just my lack of knowledge for how to code the querystring into the command.
(note: I am using the Northwind database as a testing platform right now)
Here is my code. The area I’m having problems with is in bold. I know its wrong now and I’ve tried all the variations I know to try
<asp:SqlDataSource ID=“SqlDataSource1” runat=“server” ConnectionString=“<%$ ConnectionStrings:NorthwindConnectionString %>”
SelectCommand=“SELECT [CustomerID], [CompanyName], [City] FROM [Customers] WHERE [City]='<% Request.QueryString[“cid”] %>'”></asp:SqlDataSource>
<asp:GridView ID=“GridView1” runat=“server” AutoGenerateColumns=“False” DataKeyNames=“CustomerID”
DataSourceID=“SqlDataSource1” Width=“794px”>
<Columns>
<asp:BoundField DataField=“CustomerID” HeaderText=“CustomerID” ReadOnly=“True” SortExpression=“CustomerID” />
<asp:BoundField DataField=“CompanyName” HeaderText=“CompanyName” SortExpression=“CompanyName” />
<asp:BoundField DataField=“City” HeaderText=“City” SortExpression=“City” />
</Columns>
</asp:GridView>
Any help would be appreciated.