ObjectDataSource and GridView

E

Eiriken

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top