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

Grid dropdown list validation error

3 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Todd
Top achievements
Rank 1
Todd asked on 11 Feb 2009, 05:26 PM
Hello,

I have a grid inside a RadPageView.  The grid is set to filter, sort, insert new row, and edit a row.  One of the columns is a dropdown list for the manager name.  I put validation code on all the required columns and everything works until I added validation to the dropdown list.  Why am I getting the following error message?  Thank you very much for your help.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 98:                 invProdNameValidator.ControlToValidate = invProdNameEditor.DropDownListControl.ID;
Line 99:                 invProdNameValidator.ErrorMessage = "* InvProdName is a required filed";
Line 100:                invProdNameCell.Controls.Add(invProdNameValidator);
Line 101:
Line 102:                RequiredFieldValidator riskIdValidator = new RequiredFieldValidator();

Source File: C:\Users\thoeft.ALPHAMETRIX\Documents\Visual Studio 2008\Projects\Risk Maint Portal\Risk Maint Portal\Default.aspx.cs    Line: 100

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Risk_Maint_Portal._Default.RadGrid2_ItemCreated(Object sender, GridItemEventArgs e) in C:\Users\thoeft.ALPHAMETRIX\Documents\Visual Studio 2008\Projects\Risk Maint Portal\Risk Maint Portal\Default.aspx.cs:100
   Telerik.Web.UI.RadGrid.OnItemCreated(GridItemEventArgs e) +126
   Telerik.Web.UI.RadGrid.CallOnItemCreated(GridItemEventArgs e) +39
   Telerik.Web.UI.GridEditFormItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +365
   Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group) +979
   Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[] columns, ControlCollection controls) +187
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1077
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +782
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   Telerik.Web.UI.GridTableView.PerformSelect() +28
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.GridTableView.DataBind() +364
   Telerik.Web.UI.GridTableView.Rebind() +98
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +395
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +191
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +165
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


Here is the code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Risk_Maint_Portal._Default" %>

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="ScriptManager1" runat="server"
        EnableTheming="True">
    </telerik:RadScriptManager>
    <div>
    
        <telerik:RadTabStrip ID="RadTabStrip1" runat="server" Height="29px"
            MultiPageID="RadMultiPage1" Skin="Gray" Width="1149px">
            <Tabs>
                <telerik:RadTab runat="server" PageViewID="RadPageView2"
                    Text="Master Contracts">
                </telerik:RadTab>
                <telerik:RadTab runat="server" PageViewID="RadPageView3" Text="Risk Limits">
                </telerik:RadTab>
            </Tabs>
        </telerik:RadTabStrip>
        <telerik:RadMultiPage ID="RadMultiPage1" runat="server">
            <telerik:RadPageView ID="RadPageView2" runat="server">
                <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                    ConnectionString="<%$ ConnectionStrings:GrapevineConnectionString %>"
                    DeleteCommand="DELETE FROM [master_Contract] WHERE [DWID] = @DWID"
                    InsertCommand="INSERT INTO [master_Contract] ([RiskID], [TFPRID], [ExchCode], [FutCode], [MarketID], [InstType], [ContractDes], [Market], [Sector1], [Sector2]) VALUES (@RiskID, @TFPRID, @ExchCode, @FutCode, @MarketID, @InstType, @ContractDes, @Market, @Sector1, @Sector2)"
                    SelectCommand="SELECT RiskID, TFPRID, ExchCode, FutCode, MarketID, InstType, ContractDes, Market, Sector1, Sector2 FROM master_Contract ORDER BY Market, Sector1"
                    
                    UpdateCommand="UPDATE [master_Contract] SET [RiskID] = @RiskID, [TFPRID] = @TFPRID, [ExchCode] = @ExchCode, [FutCode] = @FutCode, [MarketID] = @MarketID, [InstType] = @InstType, [ContractDes] = @ContractDes, [Market] = @Market, [Sector1] = @Sector1, [Sector2] = @Sector2 WHERE [DWID] = @DWID">
                    <DeleteParameters>
                        <asp:Parameter Name="DWID" Type="Int32" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="RiskID" Type="Int32" />
                        <asp:Parameter Name="TFPRID" Type="Int32" />
                        <asp:Parameter Name="ExchCode" Type="String" />
                        <asp:Parameter Name="FutCode" Type="String" />
                        <asp:Parameter Name="MarketID" Type="String" />
                        <asp:Parameter Name="InstType" Type="String" />
                        <asp:Parameter Name="ContractDes" Type="String" />
                        <asp:Parameter Name="Market" Type="String" />
                        <asp:Parameter Name="Sector1" Type="String" />
                        <asp:Parameter Name="Sector2" Type="String" />
                        <asp:Parameter Name="DWID" Type="Int32" />
                    </UpdateParameters>
                    <InsertParameters>
                        <asp:Parameter Name="RiskID" Type="Int32" />
                        <asp:Parameter Name="TFPRID" Type="Int32" />
                        <asp:Parameter Name="ExchCode" Type="String" />
                        <asp:Parameter Name="FutCode" Type="String" />
                        <asp:Parameter Name="MarketID" Type="String" />
                        <asp:Parameter Name="InstType" Type="String" />
                        <asp:Parameter Name="ContractDes" Type="String" />
                        <asp:Parameter Name="Market" Type="String" />
                        <asp:Parameter Name="Sector1" Type="String" />
                        <asp:Parameter Name="Sector2" Type="String" />
                    </InsertParameters>
                </asp:SqlDataSource>
            </telerik:RadPageView>
            <telerik:RadPageView ID="RadPageView3" runat="server">
                <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                    ConnectionString="<%$ ConnectionStrings:GrapevineConnectionString %>"                    
                    
                    SelectCommand="SELECT DISTINCT c.InvProdName, c.CellID, r.RiskID, r.AverageContracts, r.ContractLimit, r.SpreadLimit, r.StartDate, r.EndDate FROM risk_Limits AS r INNER JOIN cellInfo1 AS c ON r.CellID = c.CellID ORDER BY c.InvProdName, r.RiskID, r.EndDate"></asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSource3" runat="server"
                    ConnectionString="<%$ ConnectionStrings:GrapevineConnectionString %>"
                    SelectCommand="SELECT DISTINCT InvProdName, CellID FROM cellInfo1 WHERE (IsActual = 1)">
                </asp:SqlDataSource>
                <telerik:RadGrid ID="RadGrid2" runat="server" AllowAutomaticDeletes="True"
                    AllowAutomaticInserts="True" AllowFilteringByColumn="True" AllowPaging="True"
                    AllowSorting="True" DataSourceID="SqlDataSource2" GridLines="None"
                    onitemcreated="RadGrid2_ItemCreated"
                    GroupingEnabled="False">
                    <HeaderContextMenu>
                        <CollapseAnimation Duration="200" Type="OutQuint" />
                    </HeaderContextMenu>
                    <MasterTableView AllowMultiColumnSorting="True" AutoGenerateColumns="False"
                        CommandItemDisplay="Top" DataSourceID="SqlDataSource2"
                        GridLines="Both" GroupsDefaultExpanded="False" PageSize="40">
                        <Columns>
                            <telerik:GridEditCommandColumn>
                            </telerik:GridEditCommandColumn>
                            <telerik:GridDropDownColumn UniqueName="InvProdName" ListTextField="InvProdName"
                            ListValueField="InvProdName" DataSourceID="SqlDataSource3" HeaderText="InvProdName"
                            DataField="InvProdName" AllowSorting="true">
                            </telerik:GridDropDownColumn>
                            <telerik:GridBoundColumn DataField="CellID" HeaderText="CellID"
                                SortExpression="CellID" UniqueName="CellID" DataType="System.Int32">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="RiskID" DataType="System.Int32"
                                HeaderText="RiskID" SortExpression="RiskID"
                                UniqueName="RiskID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="AverageContracts" DataType="System.Decimal"
                                HeaderText="AverageContracts" SortExpression="AverageContracts"
                                UniqueName="AverageContracts">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ContractLimit" DataType="System.Decimal"
                                HeaderText="ContractLimit" SortExpression="ContractLimit"
                                UniqueName="ContractLimit">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="SpreadLimit" DataType="System.Decimal"
                                HeaderText="SpreadLimit" SortExpression="SpreadLimit"
                                UniqueName="SpreadLimit">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="StartDate" DataType="System.DateTime"
                                HeaderText="StartDate" SortExpression="StartDate" UniqueName="StartDate">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="EndDate" DataType="System.DateTime"
                                HeaderText="EndDate" SortExpression="EndDate" UniqueName="EndDate">
                            </telerik:GridBoundColumn>
                        </Columns>
                        <GroupByExpressions>
                            <telerik:GridGroupByExpression>
                            <SelectFields>
                                <telerik:GridGroupByField FieldName="InvProdName" FieldAlias="InvProdName" HeaderText=" " HeaderValueSeparator="" />
                            </SelectFields>
                                <GroupByFields>
                                    <telerik:GridGroupByField FieldAlias="InvProdName" FieldName="InvProdName"
                                        FormatString="" HeaderText="" />
                                </GroupByFields>
                            </telerik:GridGroupByExpression>
                        </GroupByExpressions>
                        <EditFormSettings>
                            <EditColumn UniqueName="EditCommandColumn1">
                            </EditColumn>
                        </EditFormSettings>
                        <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                    </MasterTableView>
                    <ClientSettings AllowDragToGroup="True">
                    </ClientSettings>
                    <FilterMenu>
                        <CollapseAnimation Duration="200" Type="OutQuint" />
                    </FilterMenu>
                </telerik:RadGrid>
            </telerik:RadPageView>
        </telerik:RadMultiPage>
    
    </div>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="i0" />
                    <telerik:AjaxUpdatedControl ControlID="i1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    </form>
</body>
</html>

Code Behind:
protected void RadGrid2_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem item = e.Item as GridEditableItem;

                GridDropDownListColumnEditor invProdNameEditor = (GridDropDownListColumnEditor)item.EditManager.GetColumnEditor("InvProdName");
                //GridTextBoxColumnEditor invProdNameEditor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("InvProdName");
                GridTextBoxColumnEditor riskIdEditor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("RiskID");
                GridTextBoxColumnEditor startDateEditor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("StartDate");
                GridTextBoxColumnEditor endDateEditor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("EndDate");

                
                TableCell invProdNameCell = (TableCell)invProdNameEditor.DropDownListControl.Parent;
                TableCell riskIdCell = (TableCell)riskIdEditor.TextBoxControl.Parent;
                TableCell startDateCell = (TableCell)startDateEditor.TextBoxControl.Parent;
                TableCell endDateCell = (TableCell)endDateEditor.TextBoxControl.Parent;

                RequiredFieldValidator invProdNameValidator = new RequiredFieldValidator();
                invProdNameEditor.DropDownListControl.ID = "InvProdNameReqValidator";
                invProdNameValidator.ControlToValidate = invProdNameEditor.DropDownListControl.ID;
                invProdNameValidator.ErrorMessage = "* InvProdName is a required filed";
                invProdNameCell.Controls.Add(invProdNameValidator);

                RequiredFieldValidator riskIdValidator = new RequiredFieldValidator();
                riskIdEditor.TextBoxControl.ID = "RiskIDReqValidator";
                riskIdValidator.ControlToValidate = riskIdEditor.TextBoxControl.ID;
                riskIdValidator.ErrorMessage = "* RiskID is a required filed";
                riskIdCell.Controls.Add(riskIdValidator);

                RequiredFieldValidator startDateValidator = new RequiredFieldValidator();
                startDateEditor.TextBoxControl.ID = "StartDateReqValidator";
                startDateValidator.ControlToValidate = startDateEditor.TextBoxControl.ID;
                startDateValidator.ErrorMessage = "* StartDate is a required filed";
                startDateCell.Controls.Add(startDateValidator);

                RequiredFieldValidator endDateValidator = new RequiredFieldValidator();
                endDateEditor.TextBoxControl.ID = "EndDateReqValidator";
                endDateValidator.ControlToValidate = endDateEditor.TextBoxControl.ID;
                endDateValidator.ErrorMessage = "* EndDate is a required filed";
                endDateCell.Controls.Add(endDateValidator);
            }





3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 16 Feb 2009, 01:41 PM
Hello Todd,

Unfortunately I could not reproduce the described issue and I have created a test project in my attempt to recreate this abnormality.

The code below shows how I validate the DropDownList control inside built-in GridDropDownColumn:
<telerik:GridDropDownColumn DataField="ShipVia" DataType="System.Int32"  
            HeaderText="ShipVia" SortExpression="ShipVia" UniqueName="ShipVia" 
            ListTextField="CompanyName" ListValueField="ShipperID" DropDownControlType="DropDownList" 
            DataSourceID="SqlDataSource2" AllowSorting="true"
        </telerik:GridDropDownColumn> 
... 
 
<%--Should set validation settings in order to stop postback--%> 
<ValidationSettings EnableValidation="true" ValidationGroup="DropDownValidate" /> 

And the code behind:
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem item = e.Item as GridEditableItem; 
            GridDropDownListColumnEditor shipViaEditor = (GridDropDownListColumnEditor)item.EditManager.GetColumnEditor("ShipVia"); 
            DropDownList DDLControl = shipViaEditor.DropDownListControl; 
            DDLControl.ValidationGroup = "DropDownValidate"
            TableCell cell = (TableCell)DDLControl.Parent; 
 
            RequiredFieldValidator shipViaValidator = new RequiredFieldValidator(); 
            shipViaValidator.ControlToValidate = DDLControl.ID; 
            shipViaValidator.ErrorMessage = "* InvProdName is a required filed"
            shipViaValidator.InitialValue = "Select"
            shipViaValidator.Text = "*"
            shipViaValidator.ValidationGroup = "DropDownValidate"
            cell.Controls.Add(shipViaValidator); 
        } 
    } 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem item = e.Item as GridEditableItem; 
            GridDropDownListColumnEditor shipViaEditor = (GridDropDownListColumnEditor)item.EditManager.GetColumnEditor("ShipVia"); 
            DropDownList DDLControl = shipViaEditor.DropDownListControl; 
            DDLControl.Items.Insert(0, new ListItem("Select""Select")); 
        } 
    } 

As you notice, I have set a validation group and more important, the InitialValue property, in order to know when the selected value is not allowed. When the ItemDataBound event is raised I have inserted the initial value. Thus the DropDownControl is validated.

Best regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Eric Skaggs
Top achievements
Rank 2
answered on 19 Oct 2009, 03:08 PM
Hello,

I'm not able to obtain a reference to the TableCell that should be the Parent control of the dropdown list.

Here's the markup for my RadGrid:
    <telerik:RadGrid ID="grdProcessingInline" runat="server" 
    Width="800px" 
    Skin="Office2007" 
    PageSize="100" 
    AutoGenerateColumns="false" 
    OnNeedDataSource="grdProcessingInline_NeedDataSource" 
    OnItemCommand="grdProcessingInline_ItemCommand" 
    OnItemDataBound="grdProcessingInline_ItemDataBound" 
    OnPreRender="grdProcessingInline_PreRender" 
    OnItemCreated="grdProcessingInline_ItemCreated" 
    > 
        <ClientSettings> 
            <Scrolling AllowScroll="True"/>  
            <ClientEvents OnGridCreated="GridCreated" /> 
        </ClientSettings> 
        <MasterTableView EditMode="InPlace">  
           <HeaderStyle Wrap="false" Font-Bold="true" /> 
            <Columns> 
                <telerik:GridTemplateColumn HeaderText="Action" UniqueName="Action">  
                    <ItemStyle HorizontalAlign="Center" Wrap="false" /> 
                    <ItemTemplate> 
                        <asp:LinkButton Font-Underline="true" ForeColor="Blue" ID="lbtnEditInline" runat="server" CommandName="Edit" Visible='<%# grdProcessingInline.EditIndexes.Count == 0%>' Text="Edit, " CausesValidation="false" /> 
                        <asp:LinkButton Font-Underline="true" ForeColor="Blue" ID="lbtnDeleteInline" runat="server" CommandName="Delete"  Visible='<%# grdProcessingInline.EditIndexes.Count == 0%>' Text="Delete " OnClientClick="javascript:if(!confirm('This action will delete the selected processing record.  Are you sure?')){return false;}" CausesValidation="false" /> 
                        <asp:LinkButton Font-Underline="true" ForeColor="Blue" ID="lbtnUpdateInline" runat="server" CommandName="Update" Visible='<%# grdProcessingInline.EditIndexes.Count > 0%>' Text="Update, " CausesValidation="true" /> 
                        <asp:LinkButton Font-Underline="true" ForeColor="Blue" ID="lbtnCancelInline" runat="server" CommandName="Cancel" Visible='<%# grdProcessingInline.EditIndexes.Count > 0%>' Text="Cancel" CausesValidation="false" /> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridBoundColumn Display="false" HeaderStyle-Width="100px" DataField="ProcessingID" HeaderText="ProcessingID" SortExpression="ProcessingID" UniqueName="ProcessingID" ><ItemStyle HorizontalAlign="Center" Wrap="false" /></telerik:GridBoundColumn> 
                <telerik:GridDropDownColumn Display="false" HeaderStyle-Width="100px" DropDownControlType="RadComboBox" DataField="ProcessingTypeDesc" HeaderText="Process Type" SortExpression="ProcessingTypeDesc" UniqueName="ProcessingTypeDesc" ><ItemStyle HorizontalAlign="Center" Wrap="false" /></telerik:GridDropDownColumn> 
                <telerik:GridDateTimeColumn DataField="MLARcvdDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="MLA Received Date" SortExpression="MLARcvdDate" UniqueName="MLARcvdDate" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridDateTimeColumn> 
                <telerik:GridBoundColumn DataField="SentCLABy" HeaderText="Sent to CLA By" SortExpression="SentCLABy" UniqueName="SentCLABy" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridBoundColumn> 
                <telerik:GridDateTimeColumn DataField="SentCLADate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Date Sent to CLA" SortExpression="SentCLADate" UniqueName="SentCLADate" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridDateTimeColumn> 
                <telerik:GridDropDownColumn DropDownControlType="RadComboBox" HeaderText="Errors Found" SortExpression="ErrorsFoundDesc" UniqueName="ErrorsFoundDesc" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridDropDownColumn> 
                <telerik:GridBoundColumn DataField="ReviewedBy" HeaderText="Reviewed By" SortExpression="ReviewedBy" UniqueName="ReviewedBy" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridBoundColumn> 
                <telerik:GridDateTimeColumn DataField="ReviewFinalizedDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Date Review Finalized" SortExpression="ReviewFinalizedDate" UniqueName="ReviewFinalizedDate" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridDateTimeColumn> 
                <telerik:GridDateTimeColumn DataField="CLAReceivedDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="CLA Rcv'd Date" SortExpression="CLAReceivedDate" UniqueName="CLAReceivedDate" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridDateTimeColumn> 
                <telerik:GridBoundColumn DataField="Abstractor" HeaderText="Abstractor" SortExpression="Abstractor" UniqueName="Abstractor" ><ItemStyle HorizontalAlign="Left" Wrap="false"/></telerik:GridBoundColumn> 
                <telerik:GridDateTimeColumn DataField="E1EntryDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Date Entered Into E1" SortExpression="E1EntryDate" UniqueName="E1EntryDate" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridDateTimeColumn> 
                <telerik:GridDropDownColumn DropDownControlType="RadComboBox" DataField="DocErrorsDesc" HeaderText="Doc. Errors Found" SortExpression="DocErrorsDesc" UniqueName="DocErrorsDesc" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridDropDownColumn> 
                <telerik:GridDateTimeColumn DataField="DateScanned" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Date Scanned" SortExpression="DateScanned" UniqueName="DateScanned" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridDateTimeColumn> 
                <telerik:GridBoundColumn DataField="JobCodeNum" HeaderText="Job Code #" SortExpression="JobCodeNum" UniqueName="JobCodeNum" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="DealMaker" HeaderText="Dealmaker" SortExpression="DealMaker" UniqueName="DealMaker" ><ItemStyle HorizontalAlign="Center" Wrap="false"/></telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="OtherComments" HeaderText="Other Comments" SortExpression="OtherComments" UniqueName="OtherComments" ><ItemStyle HorizontalAlign="Left" Wrap="false"/></telerik:GridBoundColumn> 
            </Columns> 
        </MasterTableView> 
    </telerik:RadGrid> 
 

Here's the code for my ItemCreated and ItemDataBound events:
        protected void grdProcessingInline_ItemCreated(object o, GridItemEventArgs e)  
        {  
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
            {  
                GridEditableItem item = e.Item as GridEditableItem;  
                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)item.EditManager.GetColumnEditor("ProcessingTypeDesc");  
                DropDownList DDLControl = editor.DropDownListControl;  
                DDLControl.ValidationGroup = "Processing";  
                TableCell cell = (TableCell)DDLControl.Parent;  
 
                RequiredFieldValidator validator = new RequiredFieldValidator();  
                validator.ControlToValidate = editor.DropDownListControl.ID;  
                validator.ErrorMessage = "Required:  Processing Type";  
                validator.InitialValue = " ";  
                validator.ValidationGroup = "Processing";  
                cell.Controls.Add(validator);  
            }  
        }  
 
        protected void grdProcessingInline_ItemDataBound(object o, GridItemEventArgs e)  
        {  
            if ((e.Item is GridEditableItem) && e.Item.IsInEditMode)  
            {  
                GridEditableItem item = e.Item as GridEditableItem;  
                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)item.EditManager.GetColumnEditor("ProcessingTypeDesc");  
                DropDownList DDLControl = editor.DropDownListControl;  
                DDLControl.Items.Insert(0, new ListItem("Select""Select"));    
            }  
        }  
 

I'm encountering the error in the ItemCreated event on the following line:
cell.Controls.Add(validator);
This is because the object cell in the following line is being returned as null.
TableCell cell = (TableCell)DDLControl.Parent;

Am I missing something here?  I'm pretty sure I've got the same code used here and not seeing the results I expected.

Thank you,

Eric Skaggs
0
Accepted
Eric Skaggs
Top achievements
Rank 2
answered on 19 Oct 2009, 03:33 PM
I found a solution in another forum thread.  Here's the C# source for the ItemCreated event.  I don't really even need to do anything in the ItemDataBound event.
protected void grdProcessingInline_ItemCreated(object o, GridItemEventArgs e)     
        {     
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)     
            {     
    
                GridEditableItem editItem = (GridEditableItem)e.Item;     
                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)editItem.EditManager.GetColumnEditor("ProcessingTypeDesc");      
                TableCell cell = (TableCell)editor.ComboBoxControl.Parent;     
    
                RequiredFieldValidator validator = new RequiredFieldValidator();     
                editor.ComboBoxControl.ID = "cboProcessType";     
                validator.ControlToValidate = editor.ComboBoxControl.ID;     
                validator.ErrorMessage = "Required:  Processing Type";     
                cell.Controls.Add(validator);      
            }     
        }   

Hope that helps,

Eric Skaggs
Tags
Grid
Asked by
Todd
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Eric Skaggs
Top achievements
Rank 2
Share this question
or