We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Using hidden columns

I want to be able to hide columns from being displayed on a grid control, but will still want to sort on these fields and add new rows to the grid and the underlying database table, so therefore will need to set the values of the hidden columns within code, Is this possible?


3 Replies

SN Sridhar N Syncfusion Team October 20, 2011 03:48 PM UTC

Hi Graham,

Thanks for your interest in Syncfusion products.

Your requirement can be achieved by using VisibleColumns. Please refer the below code snippet.

[ASPX]

runat="server" DataSourceCachingMode="ViewState" ShowIndicator="False"
EnableCallbacks="False" DataMember="DefaultView" ShowGroupDropArea="False"
DragSelectionBackColor="Yellow" >












[Codebehind-C#]

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindDataSource();
//Sorting the hidden column
this.GridGroupingControl1.TableDescriptor.SortedColumns.Add("ID");
}

this.GridGroupingControl1.DataSourceControlRowUpdating += new Syncfusion.Web.UI.WebControls.Grid.Grouping.GridDataSourceControlRowUpdateEventHandler(GridGroupingControl1_DataSourceControlRowUpdating);
}

void GridGroupingControl1_DataSourceControlRowUpdating(object sender, Syncfusion.Web.UI.WebControls.Grid.Grouping.GridDataSourceControlRowUpdateEventArgs e)
{
//Set the value for hidden column
this.GridGroupingControl1.Table.CurrentRecord.SetValue("ID", "10");
e.Handled = true;
e.Cancel = true;
}



For your convenience, we have created sample and the same can be downloaded from the following link.

ColumnWidth-GridWeb-18716547.zip

Please let me know if you have any other questions or concerns.

Regards,
Sridhar.N




GG Graham Gardner November 2, 2011 04:20 PM UTC

Should this work when adding new records as follows (i.e. the first three values set are hidden columns:

protected void GridGroupingControl1_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e)
{
if (e.Record != null)

if (e.Record.Kind == Syncfusion.Grouping.DisplayElementKind.AddNewRecord && e.Action == Syncfusion.Grouping.CurrentRecordAction.BeginEditComplete)
{
CheckEntriesCount = this.GridGroupingControl1.CurrentTable.GetFilteredRecordCount() + 1;

e.Table.AddNewRecord.SetValue("CheckNo", this.txtCheckNo.Text);
e.Table.AddNewRecord.SetValue("Parish", this.cmbParish.Text);
e.Table.AddNewRecord.SetValue("CheckDate", this.calDate.Text);
e.Table.AddNewRecord.SetValue("LineNo", CheckEntriesCount);
}

}

Note format of this code was adapted from a previous question on the forum about setting values for new records. if I hide the 3 columns the record is not added, if there are visible then the row is inserted as required.



YO Yogeshwaran Syncfusion Team November 3, 2011 10:18 AM UTC

Hi Graham,

Thank you for using Syncfusion products.

Your requirement to add new record to invisible column in “CurrentRecordContextChange” event can be achieved by using “EndEditCalled” action instead of "BeginEdit Complete" because begin action will occur at Before record editing and use “DataSourceControlRowAdding” event which is used to handle “AddNewRecord“. Please refer the following snippet:

[code behind C#]


void GridGroupingControl1_DataSourceControlRowAdding(object sender, Syncfusion.Web.UI.WebControls.Grid.Grouping.GridDataSourceControlRowAddingEventArgs e)
{

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"Script","alert('ID value added')",true);

e.Handled = true;
e.Cancel = true;

}

void GridGroupingControl1_CurrentRecordContextChange(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e)
{

if (e.Record != null)

if (e.Record.Kind == Syncfusion.Grouping.DisplayElementKind.AddNewRecord && e.Action == Syncfusion.Grouping.CurrentRecordAction.EndEditCalled)
{
e.Table.AddNewRecord.SetValue("ID", 3);

}


}


For your convenience, we have created the following sample and the sample it can be download from below link:

ColumnWidth-GridWeb-903128158.zip

Please let us know if any concerns.

Regards,
Yogesh R


Loader.
Live Chat Icon For mobile
Up arrow icon