Hello,
I have a large, programmatically created grid where the customer has added the requirement that each cell edited also have an explanation or comment. So, I will need a second column of inputs in the edit form. These strings will be separate from grid table data: values will simply be passed down to the database and entered into an audit table.
I've looked around the forum and help sections, but haven't seen anything promising.
Thanks,
David
I have a large, programmatically created grid where the customer has added the requirement that each cell edited also have an explanation or comment. So, I will need a second column of inputs in the edit form. These strings will be separate from grid table data: values will simply be passed down to the database and entered into an audit table.
I've looked around the forum and help sections, but haven't seen anything promising.
Thanks,
David
5 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 31 Oct 2012, 07:30 AM
Hi,
I guess you need to add a extra fields for comments/explanations in the edit forms. You can add TextBox/Label in the EditItemTemplate of the GridTemplateColumn next to the editing field programmatically as follows.
C#:
Thanks,
Princy.
I guess you need to add a extra fields for comments/explanations in the edit forms. You can add TextBox/Label in the EditItemTemplate of the GridTemplateColumn next to the editing field programmatically as follows.
C#:
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadGrid grid =
new
RadGrid();
grid.ID =
"RadGrid1"
;
. . .
. . .
GridTemplateColumn comments =
new
GridTemplateColumn();
grid.MasterTableView.Columns.Add(comments);
comments.EditItemTemplate =
new
MyEditFormTemplate();
}
public
class
MyEditFormTemplate : IBindableTemplate
{
public
void
InstantiateIn(Control container)
{
TextBox tb1 =
new
TextBox();
tb1.ID =
"MyTextBox"
;
container.Controls.Add(tb1);
}
public
System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
{
OrderedDictionary od =
new
OrderedDictionary();
return
od;
}
}
Thanks,
Princy.
0

David
Top achievements
Rank 1
answered on 31 Oct 2012, 01:17 PM
Hi Princy,
I don't want to add new columns in the grid, but have the edit form present a pair of input fields for each proper column being edited. Would this be possible by changing the bound columns to template columns and adding an edit form template containing two text boxes: one for the data column and one for the comment?
If this can be done, I will need help with ItemCreated and UpdateCommand events. I gave up on template columns earlier, because I never quite determined how to assign the ControlToValidate from the GridTemplateColumnEditor object. This is as far as I got in the ItemCreated event:
Thanks,
David
I don't want to add new columns in the grid, but have the edit form present a pair of input fields for each proper column being edited. Would this be possible by changing the bound columns to template columns and adding an edit form template containing two text boxes: one for the data column and one for the comment?
If this can be done, I will need help with ItemCreated and UpdateCommand events. I gave up on template columns earlier, because I never quite determined how to assign the ControlToValidate from the GridTemplateColumnEditor object. This is as far as I got in the ItemCreated event:
if
(columnEditor
is
GridTemplateColumnEditor)
{
GridTemplateColumnEditor templateColumnEditor = (GridTemplateColumnEditor)columnEditor;
//TextBox test = (TextBox)templateColumnEditor.ContainerControl.Controls[0];
reqValidator.ControlToValidate = columnName;
cell = (TableCell)templateColumnEditor.ContainerControl.Controls[0].Parent;
}
else
if
(columnEditor
is
GridTextBoxColumnEditor)
{
GridTextBoxColumnEditor boundColumnEditor = (GridTextBoxColumnEditor)columnEditor;
boundColumnEditor.TextBoxControl.ID = columnName;
reqValidator.ControlToValidate = boundColumnEditor.TextBoxControl.ID;
cell = (TableCell)boundColumnEditor.TextBoxControl.Parent;
}
Thanks,
David
0

Princy
Top achievements
Rank 2
answered on 01 Nov 2012, 05:39 AM
Hi,
I am not quite sure about the requirement.Please take a look into the following code snippet I tried to give Required Field validator for the GridTemplatecolumn .
C#:
Thanks,
Princy.
I am not quite sure about the requirement.Please take a look into the following code snippet I tried to give Required Field validator for the GridTemplatecolumn .
C#:
public
class
MyEditFormTemplate : IBindableTemplate
{
protected
RequiredFieldValidator validatorTextBox;
public
void
InstantiateIn(Control container)
{
TextBox tb1 =
new
TextBox();
tb1.ID =
"MyTextBox"
;
validatorTextBox =
new
RequiredFieldValidator();
validatorTextBox.ControlToValidate =
"MyTextBox"
;
validatorTextBox.ErrorMessage =
"*"
;
container.Controls.Add(tb1);
container.Controls.Add(validatorTextBox);
}
public
System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
{
OrderedDictionary od =
new
OrderedDictionary();
return
od;
}
}
Thanks,
Princy.
0

David
Top achievements
Rank 1
answered on 01 Nov 2012, 06:28 AM
Hi Princy,
Thanks for getting back to me.
So, is it possible to have two text boxes in an edit item template and have them both presented for editing in the edit form? One will populate from the database and one will initialize empty. Then, during edit, the form should show three columns: column names, data text boxes, and then the comment text boxes. The user then has the option to change some of the data values: if a data value is changed, a comment is required. The edit form shows the first two columns by default -- it's adding the comment text boxes that I have no idea about.
As for validation, I am using custom validators during the ItemCreated event because they do type checking and type is not known during page init. The problem I had in ItemCreated was not knowing where to get the ControlToValidate reference from the GridTemplateColumnEditor. I found the reference for bound columns from the GridTextBoxColumnEditor, but templated columns are a bit trickier.
For a better idea of my project, you can look at the code in this file: Web/Spreadsheet.aspx.cs, in the project attached to this ticket: 623797.
Cheers,
David
Thanks for getting back to me.
So, is it possible to have two text boxes in an edit item template and have them both presented for editing in the edit form? One will populate from the database and one will initialize empty. Then, during edit, the form should show three columns: column names, data text boxes, and then the comment text boxes. The user then has the option to change some of the data values: if a data value is changed, a comment is required. The edit form shows the first two columns by default -- it's adding the comment text boxes that I have no idea about.
As for validation, I am using custom validators during the ItemCreated event because they do type checking and type is not known during page init. The problem I had in ItemCreated was not knowing where to get the ControlToValidate reference from the GridTemplateColumnEditor. I found the reference for bound columns from the GridTextBoxColumnEditor, but templated columns are a bit trickier.
For a better idea of my project, you can look at the code in this file: Web/Spreadsheet.aspx.cs, in the project attached to this ticket: 623797.
Cheers,
David
0
Hi,
Then you can simply add the validator to the cell and have it initialized when the edit form is loaded.
I hope this helps.All the best,
Marin
the Telerik team
You can have all kinds of controls in the EditTemplate of the GridTemplateColumn (including two or more textboxes). You can then find these controls in the code-behind (for example in the ItemCreated event) by using the FindControl method of the cell:
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
var editFormItem = e.Item
as
GridEditFormItem;
if
(editFormItem!=
null
&& editFormItem.IsInEditMode)
{
var textBox1 = editFormItem[
"TemplateColumn unique name"
].FindControl(
"MyTextBox1"
)
as
TextBox;
var textBox2 = editFormItem[
"TemplateColumn unique name"
].FindControl(
"MyTextBox2"
)
as
TextBox;
//add custom validator refering the textboxes
}
}
Then you can simply add the validator to the cell and have it initialized when the edit form is loaded.
I hope this helps.All the best,
Marin
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.