Hello,
Im trying to control a gridview through a listbox control, i want the selection made in the ListBox be part of the select query of the sqldatasource that is bound to the gridview.
How would I go about this?
You can add a ControlParameter to your SqlDataSources's SelectParameters collection.
Take a look at the following post:http://fredrik.nsquared2.com/viewpost.aspx?PostID=133
You can via the Wizard when you create your SqlDataSource, select the option to add parameters ("WHERE" button) and select the source of the value.
It still doesnt work, below is the code i have..Are the attributes maybe case sensitive or something?
<asp:SqlDataSourceID="ResourcesSource"runat="server"
SelectCommand="SELECT * FROM [resources] WHERE ([resourcetype] = @.resourcetype)"
ConnectionString="<%$ ConnectionStrings:oaeuropeConnectionString %>">
<SelectParameters>
<asp:ControlParameterControlID="ListBox1"DefaultValue="personnel"Name="resourcetype"
PropertyName="SelectedValue"Type="String"/>
</SelectParameters>
</asp:SqlDataSource>
<asp:GridViewID="GridView2"runat="server"AutoGenerateColumns="False"DataSourceID="ResourcesSource"Width="229px">
</asp:GridView>
Nevermind, it's fixed now. But I still have another question, how do I use the item selected in the listbox as a table to make a join sql statement with, like so: "SELECT * FROM [resources],[y] WHERE([resourcetype] = @.resourcetype)" where y is the item selected in the listbox. (does ListBox.SelectedValue give back an integer or the text as is displayed in the listbox?)
Make sure the table is the value of your ListBox so the SelectedValue will give you the table name. Then you need to dynamically create your select statement with server code and make sure to set a new SelectCommand for your data source control.
Dim myQuery = "SELECT * FROM [resources]," & ListBox1.SelectedValue & " WHERE ....."
mySqlDataSource.SelectCommand = myQuery
I
0 comments:
Post a Comment