How to add a Column dynamically to the datagrid to include custom expressions

Platform: ASP.NET| Category: DataGrid

<asp:DataGrid id='DataGrid1'  runat='server'></asp:DataGrid>

VB.NET


’Fill the DataSet ds with data from database
Dim dc As DataColumn
dc = New DataColumn('Total', Type.GetType('System.Double'))
dc.Expression = 'UnitPrice * UnitsInStock'
ds.Tables(0).Columns.Add(dc)

DataGrid1.DataSource = ds
DataGrid1.DataBind()

C#


//Fill the DataSet ds with data from database
DataColumn dc ; 
dc = new DataColumn('Total', Type.GetType('System.Double'));
dc.Expression = 'UnitPrice * UnitsInStock';
ds.Tables[0].Columns.Add(dc);

DataGrid1.DataSource = ds;
DataGrid1.DataBind();

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.