tri_inn Level: Regular User Registered: 26-08-2002 Posts: 395
how to create and bind datagrid writing code in asp.net
please tell me how could i create datagrid writting code which will have feature like sorting,paging,in-place editing, at runtime column add and remove.
please guide me with source code.
05-07-2004 at 05:08 AM
|
zimcoder Level: VB Lord Registered: 27-10-2003 Posts: 225
Re: how to create and bind datagrid writing code in asp.net
It is very easy to create a datagrid from code with many of the features you ask for. Lets get into the code
This declaration covers quite a bit. It declares a datagrid and sets its id to dg and indicates this is a server side control by specifying the runat as server. In this declaration we have three other important attributes set. The first is the AutoGenerateColumns="False" this allows the developer to specify which columns to bind to the datagrid rather than have all the columns in the datasource shown. The Allowsorting attribute is then set to true so that the user can sort the datagrid based on a column they choose. Allowpaging attribute is set to true so that paging capabilities can be added to the datagrid.
Let us now create the datasource.. i will use a datatable here:
DataTable dt = new DataTable();
//Add some columns
dt.Columns.Add("item",typeof (String));
dt.Columns.Add("price",typeof(float));