Using the ObjectDataSource control in ASP.net :
In this article I'm trying to explain how to work with ObjectDataSource control for displaying database data to our DataControls. During this process we can able to learn how to configure ObjectDataSource control and how to connect with DataControl. This is very simple to communicate with our Database.
Follow below steps to configure ObjectDataSource control in our Application.
Add a class file to the project by right click on project and then choose items and then Add newItem and then choose a class file available in the list like below and give a name for that and click on Add button.
If you click Add button it’s automatically ask the confirmation message for saving location purpose. It has been saved in App_code folder when you click “yes”.
Wrote below lines of code under that class.
/// Summary description for Class1
public class Class1
// TODO: Add constructor logic here
public DataSet Get_Data()
SqlConnection con = new SqlConnection("connectionstring");
SqlDataAdapter da = new SqlDataAdapter("select * from tblEmployee", con);
DataSet ds = new DataSet();
Right click on Project folder and then create new item choose webForm and give a name for that as ObjectDataSource.aspx.
Drag & drop ObjectDataSource control to the Design page and click on smart tag then choose Configure DataSource option as shown in below.
Select the classname Choose your business object drop down and then click on Next button.
Now, select the method name created under the class file then select that method and click on Finish button.
Drag & drop Gridview control on the design view and then choose DataSource then click on Ok button and then see the Gridview changes.
After configure Gridview control with ObjectDataSource see the source code of Gridview control.
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
<asp:GridView ID="GridView1" runat="server"
Now we can successfully configure object DataSource with gridview control, just press on F5 button to execute the program and see the output.
I hope this article will help you those who are looking for the same and those who are new to implement ObjectDataSource control in your applications.
This is Naveen, I completed my MCA and I have around 3 years of experience in ASP.net while implement Web Applications. For past 3 years I learn no.of Technologies while implement my applications apart from that I try to learn new technologies and I try to implement that while implement my project.