Monday, August 16, 2010

How to use the datagrid view control in c#?

1) drag and drop the datagrid control onto the design form from tool bar and say name it as ';dgridctrl';


2) Now in the code behind source file


fetch the data from the database store it in the dataset.


eg:


Dataset ds = getData();


and assign the dataset to the datasource property of the datagrid control


dgridctrl.DataSource = ds;





Bind the datagrid using DataBind function.





dgridctrl.DataBind();





Run the program see the result.How to use the datagrid view control in c#?
It is very simple





1. Drag and Drop Gridview Control on the Form


2. Create a Datasource or chane the properties of Gridviews datasource property to point to your database and table.


3. Run the program to check it works or notHow to use the datagrid view control in c#?
get the data from the table using data adapter and dataset





sqldataadapter da=new sqldataadapter(query,connection);


dataset ds=new dataset;


da.Fill(ds);


gridview1.datasource=ds;


gridview1.databind();





this will bind the data in the dataset to the gridview on the design page.do not put datasourceid in the gridview properties.

No comments:

Post a Comment