Saturday 15 May 2010

c# - How to pass a URL parameter to a ObjectDataSource SelectMethod? -


I have a small example application with articles and comments. I can view a specific article by passing the text id value in the user's URL Are:

  http: // localhost: 56079 / viewArticle.aspx? Id = 123456   

I want to use the paragraph ID to find related comments and to populate a gridview with them in the same way.

viewArticle.aspx:

  & lt; Dx: ASPxGridView id = "ASPxGridView1" runat = "server" Autogenerate column = "false" width = "100%" datasource id = "objectDateSource 1" & gt; & Lt; Columns & gt; & Lt; Dx: GridViewDataTextColumn fieldName = "field1" caption = "field # 1" visible index = "0" /> & Lt; Dx: GridViewDataTextColumn Field Name = "Field2" Caption = "Field # 2" Visible Index = "1" /> & Lt; / Column & gt; & Lt; / Dx: ASPxGridView & gt; & Lt; Asp: ObjectDataSource id = "ObjectDataSource1" runat = "server" SelectMethod = "search comments" typename = "app.catmanager" & gt; & Lt; SelectParameters & gt; & Lt; / SelectParameters & gt; & Lt; / ASP: ObjectDataSource & gt;   

If the id is "hard-coded" in the search content method, gridview is populated with the correct entries.

My only problem is passing the article ID to search methods.

  • I get a & lt;% #% & gt; "I was thinking about the style database, but it is extremely dirty, and it still does not work.

      SelectMethod =" Search Citations (<% # Request.QueryString [ Another method I've tried was the selectmethod set in codebehind like this:  
     "id"]  
      Result in this error: ObjectDataSource 'ObjectDataSource1' is a non-standard method 'Search Component (' 123456 ')' 'ObjectDataSource1.SelectMethod =' searchComments ('123456') ";   

    Not found in which there is no parameter.

      selectParameters & gt; asp: div> 

    < P> QueryStringParamete R QueryStringField = "id" /> & lt; / SelectParameters & gt;

No comments:

Post a Comment