Add Columns Dynamically to web grid

3 replies. Last post: June 18, 2012 10:32 PM by Bernard Xiang
Tags :
  • New Discussion
  • New Question
  • New Product Feedback

Hello,

I have one Editable intersoft webgrid on my ASPX page, as per the client requirement i want to add few columns to it dynamically in specific conditions. I have done the coding for the same but it is not showing me those dynamic columns initially when grid is get load first time but when i refresh the grid manually then it is showing me the data and those columns correclty. plz suggest me the exact problem bellow is the code.


ASPX page
<ISWebGrid:WebGrid ID="wgBaseRates" runat="server" Height="280px" Width="970px" OnInitializeDataSource="wgBaseRates_InitializeDataSource"
OnInitializeLayout="wgBaseRates_InitializeLayout" OnUpdateRow="wgBaseRates_OnUpdateRow" OnInitializeRow="wgBaseRates_InitializeRow">
<LayoutSettings AllowEdit="Yes" AllowColumnSizing="Yes" AllowColumnMove="No" AllowExport="Yes"
AllowSorting="Yes" PersistRowChecker="true" RowHeightDefault="-1px" EditOnClick="true">
<ClientSideEvents OnRowValidate="wgBaseRates_OnRowValidate" OnCheckBoxClick="SelectHeaderCheckbox"
OnBeforeRequest="onUpdating()" OnAfterResponseProcess="onUpdated();"/>
<StatusBarCommandStyle>
<Active CssClass="ActiveStatusBarCommandStyle" BaseStyle="Over">
</Active>
<Over CssClass="OverStatusBarCommandStyle">
</Over>
<Normal CssClass="NormalStatusBarCommandStyle">
</Normal>
</StatusBarCommandStyle>
<HeaderStyle CssClass="HeaderStyle" Height="35px" />
<FilterRowStyle CssClass="HeaderStyle" Height="20px">
</FilterRowStyle>
<CheckedRowStyle BackColor="Aqua" CustomRules="HorizontalAlign:auto">
</CheckedRowStyle>
<LostFocusRowStyle CssClass="SelectedRowStyle" />
<FocusCellStyle CssClass="FocusCellStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<StatusBarStyle CssClass="StatusBarStyle">
</StatusBarStyle>
<AlternatingRowStyle CssClass="AlternatingRowStyle" CustomRules="HorizontalAlign:auto" />
<RowStyle CssClass="RowStyle" CustomRules="HorizontalAlign:auto" />
<FrameStyle CssClass="FrameStyle">
</FrameStyle>
<NewRowStyle CssClass="NewRowStyle">
</NewRowStyle>
<EditFocusCellStyle CssClass="EditFocusCellStyle">
</EditFocusCellStyle>
<GroupRowInfoStyle CssClass="GroupRowInfoStyle">
</GroupRowInfoStyle>
<GroupByBox>
<LabelStyle CssClass="GroupByBoxLabelStyle" />
<Style CssClass="GroupByBoxStyle">
</Style>
</GroupByBox>
</LayoutSettings>
</ISWebGrid:WebGrid>
ASPX.CS
//Calling Bellow Method in Page load
public void LoadColumns()
{
//Declaring and assigning properties for grid
WebGridColumn _RowChecker = new WebGridColumn("Column1", "Column1", "Cilumn 1", Unit.Pixel(25), ColumnType.CheckBox, EditType.NoEdit, "");
WebGridColumn _BRDID = new WebGridColumn("Cilumn2", "Column2", "ID", Unit.Pixel(0), ColumnType.Text, EditType.NoEdit, "");

//WebGridColumn _HrType = new WebGridColumn(GEO_CFT_BS_RT_DETAIL_V_Domain.HR_TYPE_DESCFriendlyName, GEO_CFT_BS_RT_DETAIL_V_Domain.HR_TYPE_DESCFriendlyName, "Hr. Type", Unit.Pixel(90), ColumnType.Text, EditType.NoEdit, "");

WebGridColumn _BaseRate = new WebGridColumn("Rate","Rate", "Base Rate", Unit.Pixel(50), ColumnType.Text, EditType.TextBox, "0.00");
WebGridColumn _FringeRate = new WebGridColumn("FRate","FRate","Fringe", Unit.Pixel(50), ColumnType.Text, EditType.TextBox, "0.00");
WebGridColumn _OTBaseRate = new WebGridColumn("OTBaseRate", "OTBaseRate", "OT Base Rate", Unit.Pixel(90), ColumnType.Text, EditType.TextBox, "0.00");
WebGridColumn _OTFringeRate = new WebGridColumn("OTFringeRate", "OTFringeRate", "OT Fringe Rate", Unit.Pixel(90), ColumnType.Text, EditType.TextBox, "0.00");

//Assigning additional properties to base rate details grid columns
_RowChecker.IsRowChecker = true;
_RowChecker.IsRowHeader = true;

_BaseRate.InputRequired = true;
_BaseRate.InputRequiredErrorText = "Please enter base rate";
_FringeRate.InputRequired = true;
_BaseRate.InputRequiredErrorText = "Please enter fringe";
_BaseRate.TextboxMaxlength = 6;
_FringeRate.TextboxMaxlength = 6;
_OTBaseRate.TextboxMaxlength = 6;
_OTFringeRate.TextboxMaxlength = 6;


//Adding columns to base rate details grid
wgBaseRates.RootTable.Columns.Add(_RowChecker);
//wgBaseRates.RootTable.Columns.Add(_HrType);
wgBaseRates.RootTable.Columns.Add(_BaseRate);
wgBaseRates.RootTable.Columns.Add(_FringeRate);
if (Session["OTDT"] != null)
{
wgBaseRates.RootTable.Columns.Add(_OTBaseRate);
wgBaseRates.RootTable.Columns.Add(_OTFringeRate);

}

wgBaseRates.RootTable.Columns.Add(_BRDID);

}
protected void wgBaseRates_InitializeDataSource(object sender, DataSourceEventArgs e)
{
//Populating datatable and assigning to datasource.
e.DataSource = CreateNewDatatable(_Dtcopy);
}





Hi Rahul,

Glad to hear that you already solved the problem. If you have question please don't hesitate to ask us. Thank you for your feedback.


Regards,

Bernard

All times are GMT -5. The time now is 12:31 AM.
Previous Next