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

Exception: 'System.OutOfMemoryException' was thrown when there is 2000+ data need to be bind in RadComboBox inside RadGrid

8 Answers 509 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Priyanka
Top achievements
Rank 1
Priyanka asked on 10 Aug 2015, 03:45 AM

I have a RadGrid and a RadComboBox outside of RadGrid (say comboOutside), inside a Web Form.
Inside RadGrid, there is 1 more RadComboBox (say comboRadGrid). On selection of items from comboOutside, comboRadGrid is bind i.e., If item 'Company' is selected from comboOutside, then all the company names will be bind in comboRadGrid; and then user select specific company from comboRadGrid and records are added in RadGrid.

For all items, functionality is working fine but I am facing issue in binding of a specific comboOutside item. i.e., When I choose a specific item from comboOutside, say I have 100 items inside comboOutside, and when I select 35th items from it, then comboRadGrid always throw this error while binding records for 35th item (since 35th item has 2000+ records to bind in comboRadGrid)
Error is attached below: 

Funcitonality is working fine for all the items except 1 specific item of RadComboBox. I don't understand why. Due to this I am unable to add records in RadGrid
Below is my code- 

C# code​

public DataTable GetAccCode(string CompanyCode)
    {
        SqlConnection con = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("[Invoice].[usp_tbl_AccountCode_DL_Test]", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@CompanyCode", CompanyCode);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        try
        {
            con.Open();
            da.Fill(dt);
            con.Close();
        }
        catch (Exception ex)
        {
        }
        return dt;
    }
protected void RGGSTAcCode_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            //bind dropdwon while "Add"
            string CompanyCode = ddlCompany.SelectedValue.ToString();
            GridEditableItem item = (GridEditableItem)e.Item;
 
            //code to bind inside RadComboBox list  
            RadComboBox rcb = (RadComboBox)item.FindControl("ddlAccountCode");
            rcb.DataSource = GetAccCode(CompanyCode);
            rcb.DataTextField = "AccountDescription";
            rcb.DataValueField = "AccountCodeID";
            rcb.DataBind();
            rcb.Items.Insert(0, new RadComboBoxItem("- Select -", string.Empty));
 
            Session["AccCode"] = rcb.SelectedValue.ToString();
            string a = rcb.SelectedValue.ToString();
 
            //Select particular dropdown value while "Edit"
            Label lblAcCode2 = item.FindControl("lblAcCode2") as Label;
            if (!string.IsNullOrEmpty(lblAcCode2.Text))
            {
                rcb.SelectedValue = lblAcCode2.Text;
                rcb.SelectedItem.Text = lblAcCode2.Text;
            }
        }
    }
     //code to bind outside RadComboBox list
        protected void BindComapnyDL()
        {
            SqlConnection con = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand("General.usp_tbl_BuyerCode_Query", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            try
            {
                con.Open();
                da.Fill(dt);
                con.Close();
            }
            catch (Exception ex)
            {
            }
 
            ddlCompany.DataTextField = "Title";
            ddlCompany.DataValueField = "Code";
            ddlCompany.DataSource = dt;
            ddlCompany.DataBind();
 
            Session["Comp"] = ddlCompany.SelectedValue.ToString();
            string a = ddlCompany.SelectedValue.ToString();     
        }
 
        //RadComboBox select index changed event
        protected void ddlCompany_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (ddlCompany.SelectedValue == null || ddlCompany.SelectedValue == "")
            {
                GridCommandItem cmditem = (GridCommandItem)RGGSTAcCode.MasterTableView.GetItems(GridItemType.CommandItem)[0];
                System.Web.UI.WebControls.Button ctrl = (System.Web.UI.WebControls.Button)cmditem.FindControl("AddNewRecordButton");
                ctrl.Enabled = false;
 
                System.Web.UI.WebControls.LinkButton btn = (System.Web.UI.WebControls.LinkButton)cmditem.FindControl("InitInsertButton");
                btn.Enabled = false;
 
                string content = "Please select company first";
                ScriptManager.RegisterStartupScript(this, typeof(string), "Successful", "alert('" + content + "');", true);
            }
            else
            {
                RGGSTAcCode.Rebind();
            }
        }

HTML Code:

 

<telerik:RadComboBox ID="ddlCompany" runat="server" Height="200" Width="240"
          DropDownWidth="310" EmptyMessage="- Select Product -" HighlightTemplatedItems="true" CausesValidation="false"
          Filter="Contains" AppendDataBoundItems="true" AllowCustomText="true" AutoPostBack="true"
          DataTextField="Title" DataValueField="Code" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged">
        </telerik:RadComboBox>
 
<telerik:RadGrid ID="RGGSTAcCode" runat="server"
                   ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true" EmptyDataText="No record available."
                   AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
                   OnNeedDataSource="RGGSTAcCode_NeedDataSource" OnItemDataBound="RGGSTAcCode_ItemDataBound"
                   OnInsertCommand="RGGSTAcCode_InsertCommand" OnDeleteCommand="RGGSTAcCode_DeleteCommand"
                   OnUpdateCommand="RGGSTAcCode_UpdateCommand" OnItemCommand="RGGSTAcCode_ItemCommand">
                  <mastertableview ShowHeadersWhenNoRecords="true" autogeneratecolumns="false" datakeynames="AccountCodeID" InsertItemDisplay="Top"
                    insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" CommandItemDisplay="Top" ClientIDMode="Static">                                  
                         <Columns>
                             <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
 
                             <telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
                                <ItemTemplate>
                                  <asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                   <asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
 
                                   <telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="240"
                                       DropDownWidth="310" HighlightTemplatedItems="true" CausesValidation="true"
                                       Filter="Contains" AppendDataBoundItems="true" DataTextField="AccountDescription" DataValueField="AccountCodeID">
                                   </telerik:RadComboBox>
                                </EditItemTemplate>
                             </telerik:GridTemplateColumn>
 
                             <telerik:GridBoundColumn DataField="AccountDescription" HeaderText="Description" UniqueName="AccountDescription" SortExpression="AccountDescription" InsertVisiblityMode="AlwaysHidden" ReadOnly="true" ></telerik:GridBoundColumn>
                             <telerik:GridBoundColumn aggregate="SUM" DataField="Amount" HeaderText="Amount" FooterAggregateFormatString="Total : {0:###,##0.00}" DataFormatString="{0:n}" FooterStyle-BackColor="#ffc04c" UniqueName="Amount" SortExpression="Amount"></telerik:GridBoundColumn>
                             <telerik:GridBoundColumn DataField="Remark" HeaderText="IFCA Remark" UniqueName="Remark" SortExpression="Remark">
 
                             </telerik:GridBoundColumn>   
 
                             <telerik:GridButtonColumn ConfirmTextFormatString="Are you sure you want to Delete {0} Account Code?" ConfirmTextFields="AccountCodeID"
                             ConfirmDialogType="RadWindow" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"></telerik:GridButtonColumn>                                                                           
                      </Columns>
                      <EditFormSettings>
                         <EditColumn ButtonType="ImageButton" />
                      </EditFormSettings>
                      <CommandItemSettings AddNewRecordText="Add new record" RefreshText="Refresh"></CommandItemSettings>
                  </mastertableview>
                </telerik:RadGrid>

 Please let me know how to resolve. What shall I change in my code.

I have to populate/bind the RadComboBox (comboRadGrid) which is inside of RadGrid, based on the Items that are outside of RadGrid of RadComboBox (comboOutside). Please note that I am very new in Telerik and asp.net Please let me know how to modify my comboRadGrid binding code (based on outside Combo List items) so that this issue do not occur again ? Please reply​

 

8 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 10 Aug 2015, 03:49 PM
Hello Priyanka,

I recommend you to check the suggestions provided in the following post:
http://www.telerik.com/forums/radgrid-becomes-too-slow-when-binding-over-100-records#qxa2LUwVA0WYQpqmpwjrTg

Hope this helps.

Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Priyanka
Top achievements
Rank 1
answered on 11 Aug 2015, 02:01 AM

Hi Eyup,

Thank you so much for the reply.

I would like to again highlight the issue I am facing. There are 2 RadComboBox in my web page. 1st RadComboBox (say ComboOutside) is outside of RadGrid and 2nd RadComboBox (say ComboInGrid) is inside the RadGrid in EditItemTemplate.

I am binding the "ComboInGrid" based on the items selected from "ComboOutside" i.e., If suppose ComboOutside has following items: Countr​ies, Companies, Employees, etc. and suppose if user has selected 'Companies' item from it, then ComboInGrid will bind all the company names. 

Sometimes ComboInGrid has 200 items and sometimes 20,000+ items based on item selection from ComboOutside.

Now, when there are 20,000+ records to bind in ComboInGrid Radcombobox, it takes lot of time to load and then shows the attached errors (mostly shows: Error occurred during a cryptographic operation. error), without loading the records in ComboInGrid ComboBox.

I tried to search many articles based on my issue then I got to know that Load On Demand mechanism works in this case.

For this, I tried to follow this article: http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/troubleshooting/optimizing-the-combobox

But since I have to bind the RadComboBox which is inside EditItemTemplate of RadGrid, so I am unable to implement it using above link. I want same functionality which is described here: http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx (server side) ,but inside RadGrid's RadComboBox.

Please Note that I am very new in Telerik and if possible please provide me the sample code so that my issue get resolved and I am able to get the desired result for 20,000+ records to bind in RadcomboBox without any exception.

The code I tried till now is as below:

C# code:

public DataTable GetAccCode(string CompanyCode)
    {
        SqlConnection con = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("[Invoice].[usp_tbl_AccountCode_DL_Test]", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@CompanyCode", CompanyCode);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        try
        {
            con.Open();
            da.Fill(dt);
            con.Close();
        }
        catch (Exception ex)
        {
        }
        return dt;
    }
 
    protected void RGGSTAcCode_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            //bind dropdwon while "Add"
            string CompanyCode = ddlCompany.SelectedValue.ToString();
            GridEditableItem item = (GridEditableItem)e.Item;
 
            //if (!(e.Item is IGridInsertItem))
            //{
                RadComboBox rcb = (RadComboBox)item.FindControl("ddlAccountCode");
 
                //RadComboBoxItem preselectedItem = new RadComboBoxItem();
                //preselectedItem.Text = ((DataRowView)e.Item.DataItem)["AccountDescription"].ToString();
                //preselectedItem.Value = ((DataRowView)e.Item.DataItem)["AccountCodeID"].ToString();
                //rcb.Items.Add(preselectedItem);
                //preselectedItem.DataBind();
                //rcb.SelectedIndex = 0;
 
                rcb.DataSource = GetAccCode(CompanyCode);
                rcb.DataTextField = "AccountDescription";
                rcb.DataValueField = "AccountCodeID";
                rcb.DataBind();
                rcb.Items.Insert(0, new RadComboBoxItem("- Select -", string.Empty));
 
                Session["AccCode"] = rcb.SelectedValue.ToString();
                string a = rcb.SelectedValue.ToString();
 
                //Select particular dropdown value while "Edit"
                Label lblAcCode2 = item.FindControl("lblAcCode2") as Label;
                if (!string.IsNullOrEmpty(lblAcCode2.Text))
                {
                    rcb.SelectedValue = lblAcCode2.Text;
                    //rcb.SelectedItem.Text = lblAcCode2.Text;
                }
 
            //}
             
        }
    }
 
    protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        string c = ddlCompany.SelectedValue.ToString();
 
        SqlConnection con = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("[Invoice].[usp_tbl_AccountCode_DL_Test]", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@CompanyCode", c);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
 
        con.Open();
        da.Fill(dt);
        con.Close();
       
        RadComboBox combo = (RadComboBox)sender;
        foreach (DataRow row in dt.Rows)
        {
            RadComboBoxItem item = new RadComboBoxItem();
            item.Text = row["AccountDescription"].ToString();
            item.Value = row["AccountCodeID"].ToString();
            combo.Items.Add(item);
            item.DataBind();
        }      
    }

 HTML Code:

<telerik:RadComboBox ID="ddlCompany" runat="server" Height="200" Width="240"
         DropDownWidth="310" EmptyMessage="- Select Product -" HighlightTemplatedItems="true" CausesValidation="false"
         Filter="Contains" AppendDataBoundItems="true" AllowCustomText="true" AutoPostBack="true"
         DataTextField="Title" DataValueField="Code" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged">
       </telerik:RadComboBox>
 
       <br />
       <br />
 
       <telerik:RadAjaxPanel ID="RadAjaxPanel4" runat="server">
               <telerik:RadGrid ID="RGGSTAcCode" runat="server"
                  ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true" EmptyDataText="No record available."
                  AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
                  OnNeedDataSource="RGGSTAcCode_NeedDataSource" OnItemDataBound="RGGSTAcCode_ItemDataBound"
                  OnInsertCommand="RGGSTAcCode_InsertCommand" OnDeleteCommand="RGGSTAcCode_DeleteCommand"
                  OnUpdateCommand="RGGSTAcCode_UpdateCommand" OnItemCommand="RGGSTAcCode_ItemCommand">
                 <mastertableview ShowHeadersWhenNoRecords="true" autogeneratecolumns="false" datakeynames="AccountCodeID" InsertItemDisplay="Top"
                   insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" CommandItemDisplay="Top" ClientIDMode="Static">                                  
                        <Columns>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
                                                          
                            <telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
                               <ItemTemplate>
                                 <asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode")%>'></asp:Label>
                               </ItemTemplate>
                               <EditItemTemplate>
                                  <asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
                                   
                                  <telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="240" DropDownWidth="310" HighlightTemplatedItems="true" CausesValidation="true"      
                                      OnItemsRequested="ddlAccountCode_ItemsRequested" EnableLoadOnDemand="true"
                                      Filter="Contains" AppendDataBoundItems="true" DataTextField="AccountDescription" DataValueField="AccountCodeID">
                                  </telerik:RadComboBox>                                  
 
                               </EditItemTemplate>
                            </telerik:GridTemplateColumn>
 
                            <telerik:GridBoundColumn DataField="AccountDescription" HeaderText="Description" UniqueName="AccountDescription" SortExpression="AccountDescription" InsertVisiblityMode="AlwaysHidden" ReadOnly="true" ></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn aggregate="SUM" DataField="Amount" HeaderText="Amount" FooterAggregateFormatString="Total : {0:###,##0.00}" DataFormatString="{0:n}" FooterStyle-BackColor="#ffc04c" UniqueName="Amount" SortExpression="Amount"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Remark" HeaderText="IFCA Remark" UniqueName="Remark" SortExpression="Remark">
                                 
                            </telerik:GridBoundColumn>   
                             
                            <telerik:GridButtonColumn ConfirmTextFormatString="Are you sure you want to Delete {0} Account Code?" ConfirmTextFields="AccountCodeID"
                            ConfirmDialogType="RadWindow" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"></telerik:GridButtonColumn>                                                                           
                     </Columns>
                     <EditFormSettings>
                        <EditColumn ButtonType="ImageButton" />
                     </EditFormSettings>
                     <CommandItemSettings AddNewRecordText="Add new record" RefreshText="Refresh"></CommandItemSettings>
                 </mastertableview>
               </telerik:RadGrid>     
       </telerik:RadAjaxPanel>

 Please help me to solve it. Please reply.

0
Priyanka
Top achievements
Rank 1
answered on 11 Aug 2015, 05:02 AM

ok now my code is working fine for Load On Demand mechanism. 

I am just having below issues to ask:

1) when I click on Edit/Update image button to update the RadGrid records, nothing happens i.e., update panel does not show up.

2) I am using Load On Demand approach in RadComboBox. I want to enable search functionality in RadCombo for all the records not for ItemsPerRequest i.e., If there are 20,000+ records showing in RadComboBox in which ItemsPerRequest=50 Items, so search is done among 50 items not among 20,000+ records. Which is not accepted by user.

3) How to bind the RadComboBox selected value in Edit/Updating mode ?

Please let me know how to solve the above issues. Please reply

Below is my current code-

HTML code:

<telerik:RadComboBox ID="ddlCompany" runat="server" Height="200" Width="240"
          DropDownWidth="310" EmptyMessage="- Select Product -" HighlightTemplatedItems="true" CausesValidation="false"
          Filter="Contains" AppendDataBoundItems="true" AllowCustomText="true" AutoPostBack="true"
          DataTextField="Title" DataValueField="Code" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged">
        </telerik:RadComboBox>
 
        <br />
        <br />
 
        <telerik:RadAjaxPanel ID="RadAjaxPanel4" runat="server">
                <telerik:RadGrid ID="RGGSTAcCode" runat="server"
                   ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true" EmptyDataText="No record available."
                   AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
                   OnNeedDataSource="RGGSTAcCode_NeedDataSource" OnItemDataBound="RGGSTAcCode_ItemDataBound"
                   OnInsertCommand="RGGSTAcCode_InsertCommand" OnDeleteCommand="RGGSTAcCode_DeleteCommand"
                   OnUpdateCommand="RGGSTAcCode_UpdateCommand" OnItemCommand="RGGSTAcCode_ItemCommand">
                  <mastertableview ShowHeadersWhenNoRecords="true" autogeneratecolumns="false" datakeynames="AccountCodeID" InsertItemDisplay="Top"
                    insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" CommandItemDisplay="Top" ClientIDMode="Static">                                  
                         <Columns>
                             <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
                                                           
                             <telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
                                <ItemTemplate>
                                  <asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                   <asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
                                    
                                   <telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="240" DropDownWidth="310" HighlightTemplatedItems="true" CausesValidation="true"      
                                       OnItemsRequested="ddlAccountCode_ItemsRequested" ItemsPerRequest="50"
                                       EnableLoadOnDemand="True" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
                                       AutoPostBack="true" OnSelectedIndexChanged="ddlAccountCode_SelectedIndexChanged"
 
                                       Filter="Contains" AppendDataBoundItems="true" DataTextField="AccountDescription" DataValueField="AccountCodeID">
                                   </telerik:RadComboBox>                                  
 
                                </EditItemTemplate>
                             </telerik:GridTemplateColumn>
 
                             <telerik:GridBoundColumn DataField="AccountDescription" HeaderText="Description" UniqueName="AccountDescription" SortExpression="AccountDescription" InsertVisiblityMode="AlwaysHidden" ReadOnly="true" ></telerik:GridBoundColumn>
                             <telerik:GridBoundColumn aggregate="SUM" DataField="Amount" HeaderText="Amount" FooterAggregateFormatString="Total : {0:###,##0.00}" DataFormatString="{0:n}" FooterStyle-BackColor="#ffc04c" UniqueName="Amount" SortExpression="Amount"></telerik:GridBoundColumn>
                             <telerik:GridBoundColumn DataField="Remark" HeaderText="IFCA Remark" UniqueName="Remark" SortExpression="Remark">
                                  
                             </telerik:GridBoundColumn>   
                              
                             <telerik:GridButtonColumn ConfirmTextFormatString="Are you sure you want to Delete {0} Account Code?" ConfirmTextFields="AccountCodeID"
                             ConfirmDialogType="RadWindow" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"></telerik:GridButtonColumn>                                                                           
                      </Columns>
                      <EditFormSettings>
                         <EditColumn ButtonType="ImageButton" />
                      </EditFormSettings>
                      <CommandItemSettings AddNewRecordText="Add new record" RefreshText="Refresh"></CommandItemSettings>
                  </mastertableview>
                </telerik:RadGrid>     
        </telerik:RadAjaxPanel>

C# code:

public DataTable GetAccCode(string CompanyCode)
    {
        SqlConnection con = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("[Invoice].[usp_tbl_AccountCode_DL_Test]", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@CompanyCode", CompanyCode);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        try
        {
            con.Open();
            da.Fill(dt);
            con.Close();
        }
        catch (Exception ex)
        {
        }
        return dt;
    }
 
    protected void RGGSTAcCode_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            //bind dropdwon while "Add"
            string CompanyCode = ddlCompany.SelectedValue.ToString();
            GridEditableItem item = (GridEditableItem)e.Item;
 
            if (!(e.Item is IGridInsertItem))
            {
                RadComboBox rcb = (RadComboBox)item.FindControl("ddlAccountCode");
                rcb.DataSource = GetAccCode(CompanyCode);
                rcb.DataTextField = "AccountDescription";
                rcb.DataValueField = "AccountCodeID";
                rcb.DataBind();
                rcb.Items.Insert(0, new RadComboBoxItem("- Select -", string.Empty));
 
                //Select particular dropdown value while "Edit"
                Label lblAcCode2 = item.FindControl("lblAcCode2") as Label;
                if (!string.IsNullOrEmpty(lblAcCode2.Text))
                {
                    rcb.SelectedValue = lblAcCode2.Text;
                    rcb.SelectedItem.Text = lblAcCode2.Text;
                }
 
            }
        }
    }
 
    private const int ItemsPerRequest = 50;
 
    private static string GetStatusMessage(int offset, int total)
    {
        if (total <= 0)
            return "No matches";
 
        return String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total);
    }
 
    protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        string c = ddlCompany.SelectedValue.ToString();
 
        DataTable dt = new DataTable();
        dt = GetAccCode(c);
 
        RadComboBox combo = (RadComboBox)sender;
        
        int itemOffset = e.NumberOfItems;
        int endOffset = Math.Min(itemOffset + ItemsPerRequest, dt.Rows.Count);
        e.EndOfItems = endOffset == dt.Rows.Count;
 
        for (int i = itemOffset; i < endOffset; i++)
        {
            combo.Items.Add(new RadComboBoxItem(dt.Rows[i]["AccountDescription"].ToString(), dt.Rows[i]["AccountDescription"].ToString()));
        }
 
        e.Message = GetStatusMessage(endOffset, dt.Rows.Count);
    }
 
    protected void ddlAccountCode_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Session["AccountCodeID"] = e.Value;
        Session["AccountDescription"] = e.Text;
    }
 
public static void UpdateAccountCode(Guid accCodeID, Guid TempGUID, string accCode1, string accDesc1, string accAmount, string accRemark, string accModifiedBy)
    {
        string strcon = ConfigurationManager.ConnectionStrings["MasterDB"].ConnectionString;
        SqlConnection con = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("[Invoice].[usp_tbl_AccountCode_Update_Transaction]", con);
        cmd.CommandType = CommandType.StoredProcedure;
 
        cmd.Connection = con;
        cmd.Parameters.AddWithValue("@AccountCodeID", accCodeID);
        cmd.Parameters.AddWithValue("@RequestId", TempGUID);
        cmd.Parameters.AddWithValue("@AccountCode", accCode1);
        cmd.Parameters.AddWithValue("@AccountDescription", accDesc1);
        cmd.Parameters.AddWithValue("@Amount", accAmount);
        cmd.Parameters.AddWithValue("@Remark", accRemark);
        cmd.Parameters.AddWithValue("@ModifiedBy", accModifiedBy);
        
        con.Open();
        cmd.ExecuteNonQuery();
    }
 
    protected void RGGSTAcCode_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem item = e.Item as GridEditableItem;
        string accCodeID = item.GetDataKeyValue("AccountCodeID").ToString();
 
        string CompanyCode = ddlCompany.SelectedValue.ToString();
 
        RadComboBox rcb = (RadComboBox)item.FindControl("ddlAccountCode");
        string selectedRadAccCode = Session["AccountDescription"].ToString();
 
        ////split dropdown 2 vales //To remove spaces from start or end use .Trim() method.
        string accCode1 = selectedRadAccCode.Substring(0, selectedRadAccCode.IndexOf('-')).Trim();
        string accDesc1 = selectedRadAccCode.Substring(selectedRadAccCode.IndexOf('-') + 1).Trim();
 
        string accAmount = (item["Amount"].Controls[0] as TextBox).Text;
        string accRemark = (item["Remark"].Controls[0] as TextBox).Text;
        string accModifiedBy = "LoginUser Name";
 
        UpdateAccountCode(new Guid(accCodeID), new Guid(lblGuidId.Text), accCode1, accDesc1, accAmount, accRemark, accModifiedBy);
        RGGSTAcCode.Rebind();
    }

0
Priyanka
Top achievements
Rank 1
answered on 11 Aug 2015, 11:56 AM

I am facing 2 issues while using LoadOnDemand approach:

1) RadComboBox.SelectedValue is not displayed in Edit/Update mode. This RadComboBox is inside RadGrid.

The functionality during Edit is working fine only RadComboBox.SelectedValue is not displayed at run time. I am unable to understand why.

2) How to set the default text "- Select -" in RadComboBox which is inside the RadGrid using c# code i.e., at 0 index

Below is my code:

protected void RGGSTAcCode_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            //bind dropdwon while "Add"
            string CompanyCode = ddlCompany.SelectedValue.ToString();
            GridEditableItem item = (GridEditableItem)e.Item;
 
            if (!(e.Item is IGridInsertItem))
            {
                RadComboBox rcb = (RadComboBox)item.FindControl("ddlAccountCode");
                
                //Select particular dropdown value while "Edit"
                Label lblAcCode2 = item.FindControl("lblAcCode2") as Label;
                if (!string.IsNullOrEmpty(lblAcCode2.Text))
                {
                    rcb.SelectedValue = lblAcCode2.Text;
                    //l.Text = lblAcCode2.Text;
                    string selVal = rcb.SelectedValue;
                }
            }
        }       
    }
 
    public DataTable GetAccCode(string CompanyCode)
    {
        SqlConnection con = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("[Invoice].[usp_tbl_AccountCode_DL_Test]", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@CompanyCode", CompanyCode);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        try
        {
            con.Open();
            da.Fill(dt);
            con.Close();
        }
        catch (Exception ex)
        {
        }
        return dt;
    }
 
    //#Load on Demand
    private const int ItemsPerRequest = 50;
 
    private static string GetStatusMessage(int offset, int total)
    {
        if (total <= 0)
            return "No matches";
 
        return String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total);
    }
 
    protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        string c = ddlCompany.SelectedValue.ToString();
 
        DataTable dt = new DataTable();
        dt = GetAccCode(c); // connection string + calling SP
 
        DataView dv = new DataView(dt);
        dv.RowFilter = "AccountDescription ='" + e.Text +"' "; //Filter based on serch text
         
        RadComboBox combo = (RadComboBox)sender;
 
        int itemOffset = e.NumberOfItems;
        int endOffset = Math.Min(itemOffset + ItemsPerRequest, dt.Rows.Count);
        e.EndOfItems = endOffset == dt.Rows.Count;
 
        for (int i = itemOffset; i < endOffset; i++)
        {
            combo.Items.Add(new RadComboBoxItem(dt.Rows[i]["AccountDescription"].ToString(), dt.Rows[i]["AccountDescription"].ToString()));
        }
       
        e.Message = GetStatusMessage(endOffset, dt.Rows.Count);      
    }
 HTML code:

<telerik:RadComboBox ID="ddlCompany" runat="server" Height="200" Width="240"
          DropDownWidth="310" EmptyMessage="- Select Product -" HighlightTemplatedItems="true" CausesValidation="false"
          Filter="Contains" AppendDataBoundItems="true" AllowCustomText="true" AutoPostBack="true"
          DataTextField="Title" DataValueField="Code" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged">
        </telerik:RadComboBox>
 
        <br />
        
        <telerik:RadAjaxPanel ID="RadAjaxPanel4" runat="server">
                <telerik:RadGrid ID="RGGSTAcCode" runat="server"
                   ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true" EmptyDataText="No record available."
                   AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
                   OnNeedDataSource="RGGSTAcCode_NeedDataSource" OnItemDataBound="RGGSTAcCode_ItemDataBound"
                   OnInsertCommand="RGGSTAcCode_InsertCommand" OnDeleteCommand="RGGSTAcCode_DeleteCommand"
                   OnUpdateCommand="RGGSTAcCode_UpdateCommand" OnItemCommand="RGGSTAcCode_ItemCommand">
                  <mastertableview ShowHeadersWhenNoRecords="true" autogeneratecolumns="false" datakeynames="AccountCodeID" InsertItemDisplay="Top"
                    insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" CommandItemDisplay="Top" ClientIDMode="Static">                                  
                         <Columns>
                             <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
                                                           
                             <telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
                                <ItemTemplate>
                                  <asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                   <asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
                                    
                                   <telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="240" DropDownWidth="310" HighlightTemplatedItems="true" CausesValidation="true"      
                                       OnItemsRequested="ddlAccountCode_ItemsRequested" ItemsPerRequest="10"
                                       EnableLoadOnDemand="True" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
                                       Filter="Contains" AppendDataBoundItems="true" DataTextField="AccountDescription" DataValueField="AccountCodeID">
                                   </telerik:RadComboBox>
                                     
                                    <asp:Label ID="Label1" runat="server"></asp:Label>           
 
                                </EditItemTemplate>
                             </telerik:GridTemplateColumn>
 
                             <telerik:GridBoundColumn DataField="AccountDescription" HeaderText="Description" UniqueName="AccountDescription" SortExpression="AccountDescription" InsertVisiblityMode="AlwaysHidden" ReadOnly="true" ></telerik:GridBoundColumn>
                             <telerik:GridBoundColumn aggregate="SUM" DataField="Amount" HeaderText="Amount" FooterAggregateFormatString="Total : {0:###,##0.00}" DataFormatString="{0:n}" FooterStyle-BackColor="#ffc04c" UniqueName="Amount" SortExpression="Amount"></telerik:GridBoundColumn>
                             <telerik:GridBoundColumn DataField="Remark" HeaderText="IFCA Remark" UniqueName="Remark" SortExpression="Remark">
                                  
                             </telerik:GridBoundColumn>   
                              
                             <telerik:GridButtonColumn ConfirmTextFormatString="Are you sure you want to Delete {0} Account Code?" ConfirmTextFields="AccountCodeID"
                             ConfirmDialogType="RadWindow" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"></telerik:GridButtonColumn>                                                                           
                      </Columns>
                      <EditFormSettings>
                         <EditColumn ButtonType="ImageButton" />
                      </EditFormSettings>
                      <CommandItemSettings AddNewRecordText="Add new record" RefreshText="Refresh"></CommandItemSettings>
                  </mastertableview>
                </telerik:RadGrid>     
        </telerik:RadAjaxPanel>

 Please reply to my posted question. I myself also trying to solve it. Please someone help me, its urgent.

 

0
Eyup
Telerik team
answered on 12 Aug 2015, 10:27 AM
Hi Priyanka,

To greatly improve the performance of your configuration, please enable the AllowPaging property of the grid. As for editing grid with LoadOnDemand combobox, I am sending a sample RadGrid web site to demonstrate a basic implementation.

Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Priyanka
Top achievements
Rank 1
answered on 13 Aug 2015, 01:42 AM

Below code resolved my 1st Issue:

protected void RGGSTAcCode_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            //bind dropdwon while "Add"
            string CompanyCode = ddlCompany.SelectedValue.ToString();
            GridEditableItem item = (GridEditableItem)e.Item;
 
            if (!(e.Item is IGridInsertItem))
            {
                RadComboBox rcb = (RadComboBox)item.FindControl("ddlAccountCode");
 
                //bind combobox in Edit mode from DB when using LoadOnDemand
                RadComboBoxItem rcbi = new RadComboBoxItem();
                rcbi.Text = ((DataRowView)e.Item.DataItem)["AccountCode"].ToString() + '-' + ((DataRowView)e.Item.DataItem)["AccountDescription"].ToString();
                rcbi.Value = ((DataRowView)e.Item.DataItem)["AccountCodeID"].ToString();
                rcb.Items.Add(rcbi);
                rcbi.DataBind();
            }
        }       
    }

 Now I only have 2 issues left:

1) I want to set the Default Text in RadComboBox i.e., "-Select-" from c# code behind.

2) There is a significant lag between the time the end-user begins typing and when the filtered items show up. What I observed that the searching in RadcomboBox is done character wise not Word wise.

Please reply what is the simplest way to resolve the above to issue.
Please note that I am new in Telerik. Please reply from long time I am stuck in this.

 

 

 

 

 

0
Priyanka
Top achievements
Rank 1
answered on 15 Aug 2015, 04:44 PM

Please anyone reply to my last post in the loop. Rest is working fine.

Please reply

0
Eyup
Telerik team
answered on 17 Aug 2015, 12:25 PM
Hello Priyanka,

This behavior seems related to RadComboBox. I suggest that you continue this conversation on the following thread:
http://www.telerik.com/forums/telerik-radcombobox-takes-lot-of-time-when-doing-filter-in-it-using-loadondemand-mechanism

Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Priyanka
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Priyanka
Top achievements
Rank 1
Share this question
or