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

[Solved] GridBoundColumn Validation

2 Answers 663 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 11 Jul 2008, 01:05 PM
Hi,

I followed the instructions in the link http://www.telerik.com/help/aspnet/grid/grdvalidation.html but can not get a required validator to work.  I am using a form (rather than InPlace editing).  I am using a RadAjaxManager that is added at runtime-don't know if this would have an affect on this.  The message does not display next to the control I am validating, when I click the Update link in the form, it posts back to the server and re-displays the record before I modified the data (like remove the city to test the validator).  Here's the grid html snippet:

<telerik:RadGrid ID="RadGridCageCode" runat="server" AllowFilteringByColumn="False"AllowPaging="True" AllowSorting="True" GridLines="None" Skin="Vista" EnableAJAX="True" width="60%" AllowAutomaticDeletes="True"AllowAutomaticInserts="True" AllowAutomaticUpdates="True" OnItemCommand="RadGridCageCodeLookup_ItemCommand"DataSourceID="ObjectDataSourceCageCode" PagerStyle-Mode="NextPrevNumericAndAdvanced"OnItemDeleted="RadGridCageCodeLookup_ItemDeleted" OnItemDataBound="RadGridCageCodeLookup_ItemDataBound"OnDeleteCommand="RadGridCageCodeLookup_DeleteCommand" OnItemInserted="RadGridCageCodeLookup_ItemInserted"
OnInit="RadGridCageCodeLookup_Init" OnColumnCreated="RadGridCageCodeLookup_ColumnCreated" OnInsertCommand="RadGridCageCodeLookup_InsertCommand"
OnItemUpdated="RadGridCageCodeLookup_ItemUpdated" OnUpdateCommand="RadGridCageCodeLookup_UpdateCommand" onitemcreated="RadGridCageCodeLookup_ItemCreated" >

<ClientSettings >
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>

<PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
<MasterTableView AllowMultiColumnSorting="True" PageSize="15" CommandItemDisplay="TopAndBottom"AutoGenerateColumns="False" DataKeyNames="CageCodeID" DataSourceID="ObjectDataSourceCageCode">

<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<ExpandCollapseColumn Visible="False" Resizable="False">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>

<Columns>

<telerik:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="~\RadControls\Skins\Vista\Grid\Update.gif" EditImageUrl="~\RadControls\Skins\Vista\Grid\Edit.gif" InsertImageUrl="~\RadControls\Skins\Vista\Grid\AddRecord.gif" CancelImageUrl="~\RadControls\Skins\Vista\Grid\Cancel.gif"
UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="CageCodeID" DataType="System.Int32" HeaderText="CageCodeID" ReadOnly="True" SortExpression="ID" UniqueName="CageCodeID" Visible="false">
</telerik:GridBoundColumn>

<telerik:GridBoundColumn DataField="ManufacturerID" DataType="System.Int32" HeaderText="Mfg ID" SortExpression="ManufacturerID" UniqueName="ManufacturerID" visible="false" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CageCode" HeaderText="Cage Code" SortExpression="CageCode" UniqueName="CageCode" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Address" HeaderText="Address" SortExpression="Address" UniqueName="Address">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Address2" HeaderText="Address 2" SortExpression="Address2" UniqueName="Address2" ConvertEmptyStringToNull="false" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="City" HeaderText="City" SortExpression="City" UniqueName="City"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Province" HeaderText="State" SortExpression="Province" UniqueName="State">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Zip" HeaderText="Zip Code" SortExpression="Zip" UniqueName="Zip" DataFormatString="{0:#####-0000}" ></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Phone" HeaderText="Phone Number" SortExpression="Phone" UniqueName="Phone">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Country" HeaderText="Country" SortExpression="Country" UniqueName="Country">
</telerik:GridBoundColumn>

<
telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this record?" ButtonType="ImageButton" ImageUrl="~\RadControls\Skins\Vista\Grid\Delete.gif" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
<HeaderStyle Width="20px" />
</telerik:GridButtonColumn>

</Columns>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="false" />
</ClientSettings>

</telerik:RadGrid>

And the code behind to add the validator

protected void RadGridCageCodeLookup_ItemCreated(object sender, GridItemEventArgs e)

{

if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
    
GridEditableItem itemAddress = e.Item as GridEditableItem;
GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)itemAddress.EditManager.GetColumnEditor("City");
TableCell cell = (TableCell)editor.TextBoxControl.Parent;
RequiredFieldValidator validator = new RequiredFieldValidator();
editor.TextBoxControl.ID =
"address_req_val";
validator.ControlToValidate = editor.TextBoxControl.ID;
validator.ErrorMessage =
"Required";
validator.ID =
"valAddress";
validator.EnableClientScript =
true;
validator.Text =
"REQUIRED!";
validator.Enabled =
true;
validator.EnableViewState =
true;
cell.Controls.Add(validator);

}

}

2 Answers, 1 is accepted

Sort by
0
Accepted
Mishel
Top achievements
Rank 1
answered on 14 Jul 2008, 01:20 PM
Hi

Go through the following demo link:
Flexible server-side validation


0
Tonino
Top achievements
Rank 1
answered on 05 Jan 2010, 12:24 PM
Tags
Grid
Asked by
Gary
Top achievements
Rank 1
Answers by
Mishel
Top achievements
Rank 1
Tonino
Top achievements
Rank 1
Share this question
or