However, TextBoxControl.ID is null.
If I set the ID, then changes from "InPlace" edit forms are also null in e.Item.OwnerTableView.ExtractValuesFromItem
protected
void rgMembers_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem edititem = (GridEditableItem)e.Item;
/ /validate Percentage
GridTextBoxColumnEditor editorP = (GridTextBoxColumnEditor)edititem.EditManager.GetColumnEditor("Percentage");
TableCell cellP = (TableCell)editorP.TextBoxControl.Parent;
RangeValidator validatorP = new RangeValidator();
validatorP.ID =
"rgvPercentage";
validatorP.ControlToValidate = editorP.TextBoxControl.ID; //<-- Value is NULL
validatorP.Type =
ValidationDataType.Double;
validatorP.Display =
ValidatorDisplay.Dynamic;
validatorP.ErrorMessage =
"<br/>% must be between 0 and 100.";
validatorP.MinimumValue =
"0";
validatorP.MaximumValue =
"100";
cellP.Controls.Add(validatorP);
}
Why is the TextBoxControl.ID null ?
Seems to work with other type fields (i.e RadDatePicker.ID)
Thanks
7 Answers, 1 is accepted
Please check below code snippet its work correctly.
<telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID"> </telerik:GridBoundColumn><telerik:GridNumericColumn DataField="ID" UniqueName="TestID"> </telerik:GridNumericColumn>protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridNumericColumnEditor neditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("TestID") as GridNumericColumnEditor; string strTestID = neditor.NumericTextBox.ID; GridTextBoxColumnEditor beditor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("ID") as GridTextBoxColumnEditor; string strID = neditor.TemplateControl.ID; } }OR
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem item = e.Item as GridEditableItem; TextBox txt = (item["ID"].Controls[0] as TextBox); // assing property here }}Thanks,
Jayesh Goyani
Try the following code to add a Range Validator for Bound Column when edit mode is InPlace.
C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e){ if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem edititem = (GridEditableItem)e.Item; GridTextBoxColumnEditor editorP = (GridTextBoxColumnEditor)edititem.EditManager.GetColumnEditor("Percentage"); TableCell cellP = (TableCell)editorP.TextBoxControl.Parent; RangeValidator validatorP = new RangeValidator(); editorP.TextBoxControl.ID = "rgvPercentage"; validatorP.ControlToValidate = editorP.TextBoxControl.ID; validatorP.Type = ValidationDataType.Double; validatorP.Display = ValidatorDisplay.Dynamic; validatorP.ErrorMessage = "<br/>% must be between 0 and 100."; validatorP.MinimumValue = "0"; validatorP.MaximumValue = "100"; cellP.Controls.Add(validatorP); }}Thanks,
Shinu.
For GridBoundControl, the ID is still null whether I use TextBoxContro.ID or TemplateControl.ID
Unfortunately i couldn't replicate the issue.Please check the code snippet I tried.
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true" onitemcreated="RadGrid1_ItemCreated" onitemdatabound="RadGrid1_ItemDataBound" onitemcommand="RadGrid1_ItemCommand"> <MasterTableView EditMode="InPlace"> <Columns> <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID"></telerik:GridBoundColumn> </Columns> </MasterTableView></telerik:RadGrid>C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e){ if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem edititem = (GridEditableItem)e.Item; GridTextBoxColumnEditor editorP = (GridTextBoxColumnEditor)edititem.EditManager.GetColumnEditor("OrderID"); TableCell cellP = (TableCell)editorP.TextBoxControl.Parent; RangeValidator validatorP = new RangeValidator(); editorP.TextBoxControl.ID = "rgvPercentage"; validatorP.ControlToValidate = editorP.TextBoxControl.ID; validatorP.Type = ValidationDataType.Double; validatorP.Display = ValidatorDisplay.Dynamic; validatorP.ErrorMessage = "<br/>% must be between 0 and 100."; validatorP.MinimumValue = "0"; validatorP.MaximumValue = "100"; cellP.Controls.Add(validatorP); } } protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem editedItem = e.Item as GridEditableItem; Hashtable oldValues = new Hashtable(); e.Item.OwnerTableView.ExtractValuesFromItem(oldValues, editedItem); string val = oldValues["OrderID"].ToString();//Get the old value from the BoundColumn }}protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e){ if (e.CommandName == RadGrid.UpdateCommandName) { GridEditableItem editedItem = e.Item as GridEditableItem; Hashtable newValues = new Hashtable(); e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); string val = newValues["OrderID"].ToString(); //Get the new Value }}Hope this helps.
Thanks,
Shinu.
if you set editorP.TextBoxControl.ID = "rgvPercentage";
then that value of "OrderID" is null in newValues.
Why do you need to do this, anyway. Why does TextBoxControl.ID return null for GridBoundColumns?
Can you please provide your (full) code.?
Thanks,
Jayesh Goyani