HI,
I need to add a RequiredFieldValidator to the grid. The columns are autogenerated.
I was able to acess the column value in the InsertCommand untill I added the below code to the ItemDataBound.
How do I acess the columns in the InsertCommand?
Thanks for your help!!
I need to add a RequiredFieldValidator to the grid. The columns are autogenerated.
I was able to acess the column value in the InsertCommand untill I added the below code to the ItemDataBound.
How do I acess the columns in the InsertCommand?
Thanks for your help!!
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if ((e.Item is GridEditableItem && e.Item.IsInEditMode))
{
GridEditableItem item = e.Item as GridEditableItem;
GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor(Convert.ToString(ViewState["ColName"]));
TableCell cell = (TableCell)editor.TextBoxControl.Parent;
RequiredFieldValidator validator = new RequiredFieldValidator();
editor.TextBoxControl.ID = "txtValue";
validator.ControlToValidate = editor.TextBoxControl.ID;
validator.ErrorMessage = "*";
cell.Controls.Add(validator);
}
}
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
string tableName = rcbLkup.SelectedValue;
GridDataInsertItem row = (GridDataInsertItem)e.Item;
BLL_LkupMaintenance objLkup = new BLL_LkupMaintenance();
objLkup.ColName = Convert.ToString(ViewState["ColName"]);
//objLkup.LkupValue = row[objLkup.ColName].Text;
objLkup.LkupValue = ((TextBox)row.Controls[4].Controls[0]).Text;
objLkup.AddToLkupTable(tableName);
}
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
CellSpacing
=
"0"
GridLines
=
"None"
onprerender
=
"RadGrid1_PreRender"
onupdatecommand
=
"RadGrid1_UpdateCommand"
oninsertcommand
=
"RadGrid1_InsertCommand"
onitemdatabound
=
"RadGrid1_ItemDataBound"
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
>
</
HeaderContextMenu
>
<
MasterTableView
EditMode
=
"InPlace"
DataKeyNames
=
"ID"
CommandItemDisplay
=
"Top"
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
telerik:GridEditCommandColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
>
</
FilterMenu
>
</
telerik:RadGrid
>