Check documentation for the latest version of dhtmlxSuite General HowTos DHTMLX Docs

General HowTos

How can I assign aliases to DB columns?

You can assign aliases to the required tables or columns. For this purpose, use the word 'as' (as in any usual sql statement) in your connector's constructor.

dhtmlxTreeConnector connector = new dhtmlxTreeConnector(
   "Folders", 
   "FolderID AS ID", 
   "ParentID", 
   dhtmlxDatabaseAdapterType.SqlServer2005, 
   ConfigurationManager.ConnectionStrings["SamplesDatabase"].ConnectionString,
   "FolderName AS Text"
);

How can I attach event?

To attach event you should use EventHandler<...>. For more details on this topic, see the 'Event handling' quide.

connector.BeforeUpdate += new EventHandler<DataActionProcessingEventArgs>(
connector_BeforeUpdate
);
 
void connector_BeforeUpdate(object sender, DataActionProcessingEventArgs e)
{
   //custom code
}

How can I create a custom database error message?

To add a custom error message you can use the event onDBError and write the desired message in the appropriate handler.

public void error_details(object sender, DataActionProcessingEventArgs args)
{
   args.DataAction.Details = "DB operation was failed";
}
 
connector.OnDBError += new EventHandler<DataActionProcessingEventArgs>(error_details);

How can I deny access to a certain operation?

By default, connector allows all operations. To deny some operation use deny(name_of_operation) method that can get one of the following:select/update/insert/delete/all/none. For more details see 'Security' guide.

connector.Request.AllowedAccess = AccessRights.Update;

How can I customize the content of a cell?

You can use the ItemPrerender event to define how the content of a cell must be formatted.

dhtmlxGridConnector connector = new dhtmlxGridConnector(/*...*/);
connector.ItemPrerender += new EventHandler<ItemPrerenderEventArgs<dhtmlxGridDataItem>>(
connector_ItemPrerender
);
 
void connector_ItemPrerender(object sender,ItemPrerenderEventArgs<dhtmlxGridDataItem> e)
   {
      if (e.DataItem.Index % 2 == 0)
      e.DataItem.BgColor = "gray";
   }

How can I filter data on the server side?

You have 3 ways to filter data on the server backend:

  • by specifying additional parameters in URL (on the client side)
grid.load("some.ashx?connector=true&dhx_filter[1]=mask");
  • by using in-header filter types during the component configuration (on the client side)
mygrid.setHeader("Column A, Column B");
mygrid.attachHeader("#connector_text_filter,#connector_select_filter")
connector.BeforeSelect += new EventHandler(connector_BeforeSelect);
void connector_BeforeSelect(object sender, EventArgs e)
{
   this.Connector.Request.Rules.Add(
      new FieldRule("CreatedDate", Operator.GreaterOrEqual, "2009-01-01")
   );
}

See the guide 'Filtration' for more information.

How can I handle errors and log them?

You can enable logging by means of using the Log.Enabled property. For more details see the 'Error handling and logging' guide.

connector.Begin += new EventHandler(connector_Begin);
private StringBuilder _LogContent = new StringBuilder();
 
void connector_Begin(object sender, EventArgs e)
{
   Log.Enabled = true;
   Log.Listeners.Add(new TextWriterTraceListener(new StringWriter(this._LogContent)));
}

How can I sort data on the server side?

You have 2 ways to sort data on the server backend:

  • by specifying additional parameters in URL (on the client side)
grid.load("some.ashx?connector=true&dhx_sort[2]=asc");
  • by using the sorting type 'connector' during the component configuration (on the client side)
grid.setColSorting("connector,str,na);

See the guide 'Sorting' for more information.

How can I validate data on the client side?

dataProcessor lets you validate data on the client side. Use the setVerificator(index,method) method to define the appropriate columns and validators. See details in the related chapter of dataProcessor's documentation.

dp.setVerificator(column_index,verification_func)

How can I validate data on the server side?

To perform server-side validation you should use one of the dhtmlxConnector events stated below and specify the needed validation rules in the appropriate events' handlers functions:

connector.BeforeInsert += new EventHandler<DataActionProcessingEventArgs>(
connector_BeforeInsert
);
 
void connector_BeforeProcessing(object sender, DataActionProcessingEventArgs e)
{
   if (string.IsNullOrEmpty(e.DataAction.Data[(TableField)"title"]))
   ...
}

For more details on the server-side validation, see the guide 'Validation'.

Back to top