Reputation: 5426
I have a small example application with articles and comments. Users can view a specific Article by passing the article ID value in URL:
http://localhost:56079/viewArticle.aspx?id=123456
I want the Article id to be used to find corresponding comments and populate a gridview with them in the same form.
viewArticle.aspx:
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" Width="100%" DataSourceID="ObjectDataSource1">
<Columns>
<dx:GridViewDataTextColumn FieldName="field1" Caption="Field #1" VisibleIndex="0" />
<dx:GridViewDataTextColumn FieldName="field2" Caption="Field #2" VisibleIndex="1" />
</Columns>
</dx:ASPxGridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="searchComments"
TypeName="App.CommentManager">
<SelectParameters>
</SelectParameters>
</asp:ObjectDataSource>
If id is "hard-coded" in the searchComments method, gridview is populated with correct entries.
My only problem is passing the article id to searchComments method.
I was thinking about a <%# %>" style databinding approach, but it would be extremely dirty, and it still doesn't work.
SelectMethod="searchComments(<%# Request.QueryString["id"] %>)"
Another approach I tried was setting the selectmethod in codebehind like this:
ObjectDataSource1.SelectMethod = "searchComments('123456')";
That results in error: ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'searchComments('123456')' that has no parameters.
Upvotes: 0
Views: 2959
Reputation: 12628
You can use QueryStringParameter
in SelectParameters
section
<SelectParameters>
<asp:QueryStringParameter QueryStringField="id" Name="id"/>
</SelectParameters>
Upvotes: 1
Reputation: 22064
Pass a QueryStringParameter directly into SelectParameters - ie:
<SelectParameters>
<asp:QueryStringParameter QueryStringField="id" />
</SelectParameters>
Upvotes: 1