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

Problem with the radgrid

1 Answer 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Babu Puchakayala
Top achievements
Rank 1
Babu Puchakayala asked on 20 May 2010, 09:20 PM
Hi,

I work for comcast. I am testing telerik radgrid control performance (My manager is more specific about performance. If he likes he wants use telerik controls in project) by applying all techniques like paging, sorting, grouping, filtering, column swaping, row context  menu, header context menu. Until this it works fine. When tried to implement Form Template Edit Form I am getting error like "Multiple controls with the same ID 'UpdateButton' were found. FindControl requires that controls have unique IDs." I checked my code and looks fine for me. i dono where i am doing mistake. Please help me to solve this issue. I am getting this error in
RadGrid1_PreRender  method and  RadGrid1.Rebind(); line. Here is my code Please help me in this issue.

Thanks



public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        LoadData(); 
    } 
 
    private void LoadData() 
    { 
        SqlConnection SqlConn = new SqlConnection("uid=tempuser;password=tempuser;data source=USWASHL10015\\SQLEXPRESS;database=CCOM;"); 
        SqlCommand cmd = new SqlCommand(); 
        cmd.Connection = SqlConn
        cmd.CommandType = CommandType.StoredProcedure; 
        cmd.CommandText = "usp_testing"
        SqlDataAdapter da = new SqlDataAdapter(cmd); 
        DataSet ds = new DataSet(); 
        da.Fill(ds); 
        RadGrid1.DataSource = ds
        //RadGrid1.DataBind(); 
        //RadGrid1.ClientSettings.AllowDragToGroup = true
    } 
 
    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
    { 
        LoadData(); 
    } 
 
    protected void RadGrid1_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e) 
    { 
        LoadData(); 
    } 
 
    protected void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e) 
    { 
        switch (RadioButtonList1.SelectedValue) 
        { 
            case ("Swap"): 
                { 
                    RadGrid1.ClientSettings.ColumnsReorderMethod = GridClientSettings.GridColumnsReorderMethod.Swap; 
                    break; 
                }; 
            case ("Reorder"): 
                { 
                    RadGrid1.ClientSettings.ColumnsReorderMethod = GridClientSettings.GridColumnsReorderMethod.Reorder; 
                    break; 
                }; 
        } 
    } 
 
    protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e) 
    { 
        //if (e.Exception != null) 
        //{ 
        //    e.KeepInEditMode = true
        //    e.ExceptionHandled = true
        //    SetMessage(Server.HtmlEncode("Unable to update Products. Reason: " + e.Exception.Message).Replace("'", "&#39;").Replace("\r\n", "<br />")); 
        //} 
        //else 
        //{ 
        //    GridDataItem dataItem = (GridDataItem)e.Item; 
        //    SetMessage(" ProductID " + dataItem.GetDataKeyValue("ProductID") + " updated"); 
        //} 
 
        if (e.Exception != null) 
        { 
            e.KeepInEditMode = true
            e.ExceptionHandled = true
            DisplayMessage(true, "Employee " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"] + " cannot be updated. Reason: " + e.Exception.Message); 
        } 
        else 
        { 
            DisplayMessage(false, "Employee " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"] + " updated"); 
        } 
    } 
 
    protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e) 
    { 
        int radGridClickedRowIndex; 
 
        radGridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"]); 
 
        switch (e.Item.Text) 
        { 
            case "Edit": 
                RadGrid1.Items[radGridClickedRowIndex].Edit = true
                RadGrid1.Rebind(); 
                break; 
            case "Add": 
                RadGrid1.MasterTableView.IsItemInserted = true
                RadGrid1.Rebind(); 
                break; 
            case "Delete": 
                RadGrid1.MasterTableView.PerformDelete(RadGrid1.Items[radGridClickedRowIndex]); 
                break; 
        } 
    } 
 
    protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e) 
    { 
        if (e.Exception != null) 
        { 
            e.ExceptionHandled = true
            e.KeepInInsertMode = true
            DisplayMessage(true, "Employee cannot be inserted. Reason: " + e.Exception.Message); 
        } 
        else 
        { 
            DisplayMessage(false, "Employee inserted"); 
        } 
    } 
 
    protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e) 
    { 
        if (e.Exception != null) 
        { 
            e.ExceptionHandled = true
            DisplayMessage(true, "Employee " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"] + " cannot be deleted. Reason: " + e.Exception.Message); 
        } 
        else 
        { 
            DisplayMessage(false, "Employee " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"] + " deleted"); 
        } 
    } 
 
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked 
        { 
            GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn"); 
            editColumn.Visible = false
        } 
        else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted) 
        { 
            e.Canceled = true
        } 
        else 
        { 
            GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn"); 
            if (!editColumn.Visible) 
                editColumn.Visible = true
        } 
    } 
 
    protected void Page_PreInit(object sender, EventArgs e) 
    { 
        ConfigureGrid(); 
        CheckBox1.Checked = Convert.ToBoolean(EnableGridViewState); 
    } 
 
    public bool EnableGridViewState 
    { 
        get 
        { 
            bool? result = (bool?)Session["EnableGridViewState"]; 
            return result.GetValueOrDefault(); 
        } 
        set 
        { 
            Session["EnableGridViewState"] = value; 
        } 
    } 
 
    public void ConfigureGrid() 
    { 
        RadGrid1.EnableViewState = EnableGridViewState
    } 
 
    protected override void Render(HtmlTextWriter writer) 
    { 
        this.Label1.Text = "<b>RadGrid</b>'s ViewState size is " + RadGrid1.ViewStateSize + " bytes"; 
 
        base.Render(writer); 
    } 
 
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e) 
    { 
        EnableGridViewState = Convert.ToBoolean((sender as CheckBox).Checked); 
        Response.Redirect(Request.CurrentExecutionFilePath); 
    } 
 
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
         
        if (RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted) 
        { 
            GridColumn col1 = RadGrid1.MasterTableView.GetColumn("EditCommandColumn") as GridColumn; 
            col1.Visible = true
        } 
        else 
        { 
            GridColumn col2 = RadGrid1.MasterTableView.GetColumn("EditCommandColumn") as GridColumn; 
            col2.Visible = false
        } 
        if (!Page.IsPostBack) 
        { 
            RadGrid1.EditIndexes.Add(0); 
            RadGrid1.Rebind(); 
        } 
         
    } 
 
    private void DisplayMessage(bool isError, string text) 
    { 
        Label label = (isError) ? this.Label1 : this.Label2; 
        label.Text = text
    } 
 
 
 
aspx code 
 
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<%@ 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 id="Head1" runat="server"
    <title>Telerick Controls</title> 
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
 
        <script type="text/javascript"
        <!-- 
            function ReorderOrSwapFirstAndLastColumn() { 
                var ddlFirstColumnList = $get("ddlFirstColumnList"); 
                var ddlLastColumnList = $get("ddlLastColumnList"); 
 
                var tableView = $find("<%=RadGrid1.MasterTableView.ClientID %>"); 
                var firstColumnName = tableView.getColumnByUniqueName(ddlFirstColumnList.options[ddlFirstColumnList.selectedIndex].value).get_uniqueName(); 
                var lastColumnName = tableView.getColumnByUniqueName(ddlLastColumnList.options[ddlLastColumnList.selectedIndex].value).get_uniqueName(); 
 
                if (document.getElementById("RadioButtonList1_1").checked) { 
                    tableView.reorderColumns(lastColumnName, firstColumnName); 
                } 
                else { 
                    tableView.swapColumns(lastColumnName, firstColumnName); 
                } 
            } 
 
            function onGridCreated() { 
                LoadColumnsLists(); 
            } 
 
            function LoadColumnsLists() { 
                var ddlFirstColumnList = $get("ddlFirstColumnList"); 
                var ddlLastColumnList = $get("ddlLastColumnList"); 
                ddlFirstColumnList.options.length = 0
                ddlLastColumnList.options.length = 0
 
                var tableView = $find("<%=RadGrid1.MasterTableView.ClientID %>"); 
                if (ddlFirstColumnList && tableView && ddlLastColumnList) { 
                    for (var i = 1; i < tableView.get_columns().length; i++) { 
                        if (tableView.get_columns()[i].get_uniqueName() != "") { 
                            ddlFirstColumnList.options[ddlFirstColumnList.options.length] = new Option(tableView.get_columns()[i].get_uniqueName(), tableView.get_columns()[i].get_uniqueName()); 
                            ddlLastColumnList.options[ddlLastColumnList.options.length] = new Option(tableView.get_columns()[i].get_uniqueName(), tableView.get_columns()[i].get_uniqueName()); 
                        } 
                    } 
                    ddlLastColumnListddlLastColumnList.selectedIndex = ddlLastColumnList.options.length - 1; 
                    ddlFirstColumnList.selectedIndex = 0
                } 
            } 
         --> 
        </script> 
 
        <script type="text/javascript"
            function RowContextMenu(sender, eventArgs) { 
                var menu = $find("<%=RadMenu1.ClientID %>"); 
                var evt = eventArgs.get_domEvent(); 
                if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") { 
                    return; 
                } 
                var index = eventArgs.get_itemIndexHierarchical(); 
                document.getElementById("radGridClickedRowIndex").value = index
 
                sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true); 
 
                menu.show(evt); 
 
                evt.cancelBubble = true
                evt.returnValue = false
 
                if (evt.stopPropagation) { 
                    evt.stopPropagation(); 
                    evt.preventDefault(); 
                } 
            } 
        </script> 
 
        <%--<script type="text/javascript"
        <!-- 
            var hasChanges, inputs, dropdowns, editedRow; 
 
            function RowClick(sender, eventArgs)  
            { 
                if (editedRow && hasChanges)  
                { 
                    hasChanges = false
                    if (confirm("Update changes?"))  
                    { 
 
                        $find("<%= RadGrid1.MasterTableView.ClientID %>").updateItem(editedRow); 
                    } 
                } 
            } 
 
            function RowDblClick(sender, eventArgs) { 
                editedRow = eventArgs.get_itemIndexHierarchical(); 
                $find("<%= RadGrid1.MasterTableView.ClientID %>").editItem(editedRow); 
            } 
 
            function GridCommand(sender, args)  
            { 
                if (args.get_commandName() != "Edit")  
                { 
                    editedRow = null
                } 
            } 
 
            function GridCreated(sender, eventArgs)  
            { 
                var gridElement = sender.get_element(); 
                var elementsToUse = []; 
                inputs = gridElement.getElementsByTagName("input"); 
                for (var i = 0; i < inputs.length; i++)  
                { 
                    var lowerType = inputs[i].type.toLowerCase(); 
                    if (lowerType == "hidden" || lowerType == "button")  
                    { 
                        continue; 
                    } 
 
                    Array.add(elementsToUse, inputs[i]); 
                    inputs[i].onchange = TrackChanges
                } 
 
                dropdowns = gridElement.getElementsByTagName("select"); 
                for (var i = 0; i < dropdowns.length; i++)  
                { 
                    dropdowns[i].onchange = TrackChanges
                } 
 
                setTimeout(function() { if (elementsToUse[0]) elementsToUse[0].focus(); }, 100); 
            } 
 
            function TrackChanges(e)  
            { 
                hasChanges = true
            } 
     -->     
        </script>--%> 
 
        <script type="text/javascript"
            function ShowColumnHeaderMenu(ev, columnName) { 
                var grid = $find("<%=RadGrid1.ClientID %>"); 
                //show the header context menu for the second column in the master table with 10 left/10 top offset 
                var columns = grid.get_masterTableView().get_columns(); 
 
                for (var i = 0; i < columns.length; i++) { 
                    if (columns[i].get_uniqueName() == columnName) { 
                        columns[i].showHeaderMenu(ev, 75, 20); 
                    } 
                } 
            } 
        </script> 
 
        <script type="text/javascript"
            function RowDblClick(sender, eventArgs) { 
                sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical()); 
            } 
        </script> 
 
    </telerik:RadCodeBlock> 
</head> 
<body> 
    <h1> 
        Telerik Controls</h1> 
    <form id="form1" runat="server"
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
    <div> 
        <asp:Label ID="Label3" runat="server" Style="font-weight: bold; color: green"></asp:Label> 
        <br /> 
        <asp:CheckBox ID="CheckBox1" AutoPostBack="True" runat="server" Text="RadGrid's ViewState on/off" 
            OnCheckedChanged="CheckBox1_CheckedChanged" /> 
    </div> 
    <br /> 
    <div> 
        <asp:Label ID="Label1" runat="server" Text="Columns reorder method:"></asp:Label><br /> 
        <asp:RadioButtonList ID="RadioButtonList1" AutoPostBack="True" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" 
            RepeatLayout="Flow"
            <asp:ListItem Selected="True" Value="Swap">Swap</asp:ListItem> 
            <asp:ListItem Value="Reorder">Reorder (Insert)</asp:ListItem> 
        </asp:RadioButtonList> 
    </div> 
    <br /> 
    <select id="ddlFirstColumnList"
        <option value=""></option> 
    </select> 
    <select id="ddlLastColumnList"
        <option value=""></option> 
    </select> 
    <asp:Button ID="Button2" Text="Reorder or swap columns" OnClientClick="ReorderOrSwapFirstAndLastColumn(); return false;" 
        runat="server" /><br /> 
    Choose two columns to be reordered or swap. 
    <br /> 
    <div> 
        <id="divMsgs" runat="server"
            <asp:Label ID="Label4" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="#FF8080"></asp:Label> 
            <asp:Label ID="Label5" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="#00C000"></asp:Label> 
        </p> 
    </div> 
    <br /> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadMenu1" /> 
                    <telerik:AjaxUpdatedControl ControlID="divMsgs" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="RadMenu1"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadMenu1" /> 
                    <telerik:AjaxUpdatedControl ControlID="divMsgs" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"
        <%--<asp:Image ID="Image1" runat="server" ImageUrl="~/Image1.gif"></asp:Image>--%> 
    </telerik:RadAjaxLoadingPanel> 
    <%--    <telerik:RadCodeBlock runat="server" ID="radCodeBlock"
 
        <script type="text/javascript"
            function showFilterItem() { 
                $find('<%=RadGrid1.ClientID %>').get_masterTableView().showFilterItem(); 
            } 
            function hideFilterItem() { 
                $find('<%=RadGrid1.ClientID %>').get_masterTableView().hideFilterItem(); 
            } 
        </script> 
 
    </telerik:RadCodeBlock> 
    <div> 
        Show filtering item 
        <input id="Radio1" type="radio" runat="server" name="showHideGroup" checked="true" 
            onclick="showFilterItem()" /><label for="Radio1">Yes</label> 
        <input id="Radio2" type="radio" runat="server" name="showHideGroup" onclick="hideFilterItem()" /><label 
            for="Radio2">No</label> 
    </div>--%> 
    <input type="hidden" id="radGridClickedRowIndex" name="radGridClickedRowIndex" /> 
    <p> 
        Right-click the grid to open context menu. 
    </p> 
    <div> 
        <telerik:RadGrid ID="RadGrid1" OnSortCommand="RadGrid1_SortCommand" OnNeedDataSource="RadGrid1_NeedDataSource" 
            AllowSorting="True" PageSize="20" ShowGroupPanel="True" AllowPaging="True" AllowMultiRowSelection="True" 
            AllowFilteringByColumn="true" AutoGenerateColumns="false" EnableViewState="false" 
            runat="server" GridLines="None" OnItemUpdated="RadGrid1_ItemUpdated" AllowAutomaticDeletes="true" 
            AllowAutomaticInserts="true" AllowAutomaticUpdates="true" OnPreRender="RadGrid1_PreRender" 
            EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" EnableLinqExpressions="false" 
            OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted" OnItemCommand="RadGrid1_ItemCommand"
            <%-- Filtering code--%> 
            <%--             
        <MasterTableView  AutoGenerateColumns="false" EditMode="InPlace" AllowFilteringByColumn="True" ShowFooter="True" TableLayout="Auto"
                <Columns> 
                    <telerik:GridBoundColumn FilterControlWidth="105px" DataField="carrierName" HeaderText="carrierName" SortExpression="carrierName" 
                        UniqueName="carrierName" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="true"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn FilterControlWidth="105px" DataField="city" HeaderText="city" SortExpression="city" 
                        UniqueName="city" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="true"
                    </telerik:GridBoundColumn> 
                    <telerik:GridNumericColumn DataField="zipcode" HeaderText="zipcode" SortExpression="zipcode" 
                        UniqueName="zipcode" FilterControlWidth="40px" AutoPostBackOnFilter="false" CurrentFilterFunction="equalto" FilterDelay="4000" ShowFilterIcon="true"
                    </telerik:GridNumericColumn> 
                </Columns> 
        </MasterTableView>  
            --%> 
            <MasterTableView CommandItemDisplay="TopAndBottom" TableLayout="Fixed" DataKeyNames="sId" 
                EditMode="InPlace"
                <Columns> 
                    <telerik:GridEditCommandColumn> 
                    </telerik:GridEditCommandColumn> 
                    <telerik:GridBoundColumn UniqueName="sId" DataField="sId" HeaderText="sId" ReadOnly="True" 
                        HeaderStyle-Width="10%" SortExpression="sId" HeaderButtonType="TextButton"
                        <HeaderStyle ForeColor="Silver" /> 
                        <ItemStyle ForeColor="Gray" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="orderId" DataField="orderId" HeaderText="orderId" 
                        HeaderStyle-Width="10%" ColumnEditorID="GridTextBoxColumnEditor1" SortExpression="orderId" 
                        HeaderButtonType="TextButton" /> 
                    <telerik:GridBoundColumn UniqueName="REJ" DataField="REJ" HeaderText="REJ" HeaderStyle-Width="10%" 
                        SortExpression="REJ" HeaderButtonType="TextButton" /> 
                    <telerik:GridBoundColumn UniqueName="Desc" DataField="Desc" HeaderText="Desc" HeaderStyle-Width="10%" 
                        SortExpression="Desc" HeaderButtonType="TextButton" /> 
                    <telerik:GridBoundColumn UniqueName="Customer Name" DataField="Customer Name" HeaderText="Customer Name" 
                        HeaderStyle-Width="12%" SortExpression="Customer Name" HeaderButtonType="TextButton" /> 
                    <telerik:GridBoundColumn UniqueName="Market Name" DataField="Market Name" HeaderText="Market Name" 
                        HeaderStyle-Width="12%" SortExpression="Market Name" HeaderButtonType="TextButton" /> 
                    <telerik:GridBoundColumn UniqueName="Headend Name" DataField="Headend Name" HeaderText="Headend Name" 
                        HeaderStyle-Width="12%" SortExpression="Headend Name" HeaderButtonType="TextButton" /> 
                    <telerik:GridBoundColumn UniqueName="Site Name" DataField="Site Name" HeaderText="Site Name" 
                        HeaderStyle-Width="12%" SortExpression="Site Name" HeaderButtonType="TextButton" /> 
                    <telerik:GridBoundColumn UniqueName="Task Status" DataField="Task Status" HeaderText="Task Status" 
                        HeaderStyle-Width="10%" SortExpression="Task Status" HeaderButtonType="TextButton" /> 
                    <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" Visible="false" /> 
                </Columns> 
                <EditFormSettings EditFormType="Template"
                    <FormTemplate> 
                        <table> 
                            <tr> 
                                <td colspan="2" style="font-size: small"
                                    <b>Order Details</b> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td colspan="2"
                                    <b>Order Info:</b> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    <table> 
                                        <tr> 
                                            <td> 
                                                Country: 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                City: 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox8" runat="server" TabIndex="1"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Region: 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox9" runat="server" TabIndex="2"</asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Home Phone: 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox10" runat="server" TabIndex="3"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Birth Date: 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox11" runat="server" TabIndex="4"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Title Of Courtesy 
                                            </td> 
                                            <td> 
                                                <asp:DropDownList ID="ddlTOC" runat="server" SelectedValue='<%# Bind("TitleOfCourtesy") %>' 
                                                    DataSource='<%# (new string[] { "Dr.", "Mr.", "Mrs.", "Ms." }) %>' TabIndex="7" 
                                                    AppendDataBoundItems="True"
                                                    <asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem> 
                                                </asp:DropDownList> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </td> 
                                <td> 
                                    <table> 
                                        <tr> 
                                            <td> 
                                                Notes: 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                <asp:TextBox ID="TextBox1" Text='<%# Bind( "Notes") %>' runat="server" TextMode="MultiLine" 
                                                    Rows="5" Columns="40" TabIndex="5"
                                                </asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Address: 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                <asp:TextBox ID="TextBox6" Text='<%# Bind( "Address") %>' runat="server" TextMode="MultiLine" 
                                                    Rows="2" Columns="40" TabIndex="6"
                                                </asp:TextBox> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td colspan="2"
                                    <b>Table Info:</b> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    <table> 
                                        <tr> 
                                            <td> 
                                                OrderId: 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox2" runat="server" TabIndex="8"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                REJ: 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox3" runat="server" TabIndex="9"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Desc: 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="Textbox5" runat="server" TabIndex="10"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Customer Name 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox4" runat="server" TabIndex="11"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Market Name 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox12" runat="server" TabIndex="12"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Headend Name 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox13" runat="server" TabIndex="13"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Site Name 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox14" runat="server" TabIndex="14"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td> 
                                                Task Status 
                                            </td> 
                                            <td> 
                                                <asp:TextBox ID="TextBox15" runat="server" TabIndex="15"></asp:TextBox> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </td> 
                                <td> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td align="right" colspan="2"
                                    <asp:Button ID="btnUpdate" runat="server"
                                    </asp:Button>&nbsp; 
                                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" 
                                        CommandName="Cancel"></asp:Button> 
                                </td> 
                            </tr> 
                        </table> 
                    </FormTemplate> 
                </EditFormSettings> 
            </MasterTableView> 
            <ClientSettings AllowColumnsReorder="true" ReorderColumnsOnClient="true" AllowDragToGroup="True"
                <Resizing AllowRowResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="True" 
                    AllowColumnResize="True"></Resizing> 
                <ClientEvents OnRowClick="RowClick" OnRowDblClick="RowDblClick" OnGridCreated="GridCreated" 
                    OnCommand="GridCommand" /> 
                <ClientEvents OnGridCreated="onGridCreated" /> 
                <Scrolling AllowScroll="true" UseStaticHeaders="true" /> 
                <ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents> 
                <Selecting AllowRowSelect="true" /> 
            </ClientSettings> 
            <PagerStyle Mode="NextPrevAndNumeric" /> 
            <GroupingSettings CaseSensitive="false" ShowUnGroupButton="true" /> 
        </telerik:RadGrid> 
        <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="180px" /> 
        <telerik:RadContextMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick" 
            EnableRoundedCorners="true" EnableShadows="true"
            <Items> 
                <telerik:RadMenuItem Text="Add" /> 
                <telerik:RadMenuItem Text="Edit" /> 
                <telerik:RadMenuItem Text="Delete" /> 
            </Items> 
        </telerik:RadContextMenu> 
        <br /> 
        <br /> 
        <asp:Label ID="Label2" runat="server" EnableViewState="false" /> 
    </div> 
    </form> 
</body> 
</html> 
 

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 26 May 2010, 09:28 AM
Hello Babu,

Your code seems fine, except for RadGrid's databinding. When using advanced grid binding (with NeedDataSource event), you do not need to fetch RadGrid's data source in multiple places. You can do it only in NeedDataSource. When RadGrid needs to rebind, it will fire the NeedDataSource event, where you can pass the data.

Also, I can see that in ItemCommand you are canceling the Rebind command of the grid if there is an item in insert mode. I am not sure of the reason you do that, but this may also be causing the exception you are getting. It is generally not recommended to cancel rebind commands for RadGrid, as this may interfere with the proper functioning of the control.

Best wishes,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Babu Puchakayala
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or