ObjectDataSource and GridView

Discussion in 'ASP .Net' started by Eiriken, Jan 19, 2006.

  1. Eiriken

    Eiriken Guest

    Hello everyone,

    I am using ASP.NET 2 and trying to bind a objectdatasource to a
    gridview. By doing this the most common way by adding an
    objectdatasource to the page and by using the wizard to connect to my
    business logic everything works fine. The problem is that I find this
    quite limited and I need to do some custom work with the parameters, so
    I am trying to code everything by hand in the code behind.

    >From a security perspective, its not good at all to use the

    ControlParameter without any kind of verification of the input (for
    example
    from a TextBox). Thats why I want to handle all parameters manually.

    I have a GridView called "Vacancies". In the code behind I code my
    ObjectDataSource and connects it to the GridView. The code below is
    inside of an Onclick-event of a button named "Search".

    ObjectDataSource dsVacancies = new ObjectDataSource();
    dsVacancies.SelectMethod="SearchVacancy";";
    dsVacancies.TypeName="BusinessProcess.Vacancy";

    dsVacancies.SelectParameters.Clear();
    dsVacancies.ID = "dsVacancies";

    dsVacancies.SelectParameters.Add(new Parameter("countryId",
    TypeCode.Int32, "1"));
    dsVacancies.SelectParameters.Add(new Parameter("provincesIds",
    TypeCode.String, ""));
    dsVacancies.SelectParameters.Add(new Parameter("branchId",
    TypeCode.Int32, "0"));
    dsVacancies.SelectParameters.Add(new Parameter("freeText",
    TypeCode.String, FreeText));

    JobAdSearchResult.DataSource = dsVacancies;
    JobSearchResult.DataBind();

    I expected the GridView to populate the search result, but nothing
    happens. No error message nor any data rows. I know that my
    businesslogic works as I have filled my GridView without the
    ObjectDataSource like this:

    BusinessProcess.Vacancy vacancy = new BusinessProcess.Vacancy();
    Vacancies.DataSouce = vacancy.SearchVacancy(1, "", 0, "");
    Vacancies.DataBind();

    But I want all the great functionality the ObjectDataSource provides.

    What do I miss? I would appreciate if someone could point out some
    mistakes in my code, or even better provide a complete example.

    Thanks !

    Eirik
    Eiriken, Jan 19, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J055
    Replies:
    10
    Views:
    10,656
    chris22smith
    Mar 18, 2009
  2. Replies:
    1
    Views:
    3,442
    Brock Allen
    May 3, 2006
  3. Olivier Matrot
    Replies:
    2
    Views:
    3,291
    Walter Wang [MSFT]
    Oct 2, 2006
  4. avital
    Replies:
    0
    Views:
    564
    avital
    Nov 15, 2006
  5. David Thielen

    ObjectDataSource method as another ObjectDataSource

    David Thielen, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    229
    Steven Cheng[MSFT]
    Mar 23, 2006
Loading...

Share This Page