This is a migrated thread and some comments may be shown as answers.

format column from code behind

3 Answers 252 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 12 Jan 2012, 03:23 PM
I have a radgrid which displays data that is entered from rad editor.  The problem is that the grid shows several char values instead of the way it was entered. 

The grid is bound from code being and I dont have an option to set the format of the column to HTMLEditorColumn in desing view.  I was thinking to do this in code behind but did not know how to do that. 

can you please provide some light on the same

general structure of the code is 

RadGrid1.DataSource = DataTable
RadGrid1.DataBind()

For z = 0 To RadGrid1.MasterTableView.RenderColumns.Count - 1

If  <some condition to identify column> then
RadGrid1.MasterTableView.RenderColumns(z).  -- what should the code be here to set the correct format of the column
        End if 

Next


Also, can this be done in the pre-render event or does this need to be done somewhere else.  Any help provided will be much appreciated.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Jan 2012, 04:48 AM
Hello John,

If you are setting AutoGenerateColumns as true, you can format the columns in ColumnCreated event as shown below.
C#:
protected void grid_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
  if (e.Column.UniqueName == "UniqueName")
  {
   GridBoundColumn boundColumn = e.Column as GridBoundColumn;
  }
}
If you are explicitly defining columns, you can access the columns in ItemDataBound event and set the format accordingly.

-Shinu.
0
John
Top achievements
Rank 1
answered on 13 Jan 2012, 02:10 PM
so for the column to be of type GridHTMLEditorColumn, what property do I need to set within the suggested code block?
0
Andrey
Telerik team
answered on 17 Jan 2012, 06:40 PM
Hi,

Based on the provided information I could say that the problem is most probably caused by the DataTable object to which you are binding. Could you check what are the types of the columns in the DataTable object? Any additional information about the RadGrid declaration and the type of binding used will help us to provide better reply.

Additionally, please note that GridHTMLEditorColumn could not be created automatically by RadGrid. It should be defined declaratively in ASPX file or dynamically in code-behind. You could check this help topic for more information about the different types of column in RadGrid. Also, this topic shows how to define the structure of RadGrid statically and this shows how to define it programmatically.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
John
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or