I’m taking my first crack at ASP.NET and I’ve run into a problem with my datasource that seems like it should be very simple. Using the <controlparameter> tag to filter a datasource is working great, but I’d like to use it to define the field to be filtered as well as the value. To clarify, here’s what I have now:
<asp:SqlDataSource ID="test" runat="server" ConnectionString="<My String>"
SelectCommand="SELECT * FROM [occupants] WHERE (LastName = @LastName)">
<SelectParameters>
<asp:ControlParameter ControlID="searchText" Name="LastName" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
In this case, I have a “searchText” field further up the page that the user types into to enter a last name to search for. What I’d like to do is take this a step further with a drop down-box containg search fields - “First Name”, “Last Name”, “User ID”, etc. - that the user could use to refine the search. It seems like I should be able to just update the datasoruce like this:
<asp:SqlDataSource ID="test" runat="server" ConnectionString="<My String>"
SelectCommand="SELECT * FROM [occupants] WHERE (@SearchFor = @SearchString)">
<SelectParameters>
<asp:ControlParameter ControlID="searchText" Name="SearchString" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="searchField" Name="SearchFor" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Sadly, this does not work. I’ve checked through a fair amount of documentation on this, but I just can’t seem to find a way through. Can anyone point me in the right direction?
Thanks,
Alex
<asp:SqlDataSource ID="test" runat="server" ConnectionString="<My String>"
SelectCommand="SELECT * FROM [occupants] WHERE (LastName = @LastName)">
<SelectParameters>
<asp:ControlParameter ControlID="searchText" Name="LastName" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
In this case, I have a “searchText” field further up the page that the user types into to enter a last name to search for. What I’d like to do is take this a step further with a drop down-box containg search fields - “First Name”, “Last Name”, “User ID”, etc. - that the user could use to refine the search. It seems like I should be able to just update the datasoruce like this:
<asp:SqlDataSource ID="test" runat="server" ConnectionString="<My String>"
SelectCommand="SELECT * FROM [occupants] WHERE (@SearchFor = @SearchString)">
<SelectParameters>
<asp:ControlParameter ControlID="searchText" Name="SearchString" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="searchField" Name="SearchFor" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Sadly, this does not work. I’ve checked through a fair amount of documentation on this, but I just can’t seem to find a way through. Can anyone point me in the right direction?
Thanks,
Alex