Hi:
I have a GridView that I would likie to filter.
My GridView first line code is:
Code:
<asp:GridView ID="GridView1" runat="server" ForeColor="Black" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Round_Num,Customer_ID" DataSourceID="SqlDataSource4" EmptyDataText="There are no data records to display." >
Within the GridView I have several BoundFields, the most âcrucialâ is:
Code:
<asp:BoundField DataField="Customer_ID" HeaderText="Customer_ID" SortExpression="Customer_ID" />
I would like to filter the data âcoming backâ from the database by this Customer_ID value.
My SqlDataSource initial line is:
Code:
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$
ConnectionStrings:GolfDatabaseConnectionString1 %>"
My SelectComman initially is:
Code:
SelectCommand="SELECT * FROM RoundOfGolf"
â¦and at this point (without any filtering) I get the entire contents of my table RoundOfGolf, so all is well at this pointas far as connecting to the database and the transfer back to the GridView
To try and filter the returning data, if I change my SelectCommand to (with no other changes), I get:
Code:
SelectCommand="SELECT * from RoundOfGolf Where [Customer_ID] = @Customer_ID"
My error message is:
Must declare the scalar variable "@Customer_ID".
So now I have added a SelectParameter to my SqlDataSource which looks like:
Code:
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Customer_ID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
Now the code runs, but I get the message that âthere are no data records to display!
Thoughts:
I am able to retrieve data from my database table, so it seems that my âconnectionsâ are good, but as soon as I try and filter that data to show only certain Customer_IDs things go bad.
You thoughts would be appreciated.
Cliff