Radgrid template column maintain state on paging

20 posts, 1 answers
  1. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 15 Nov 2014 Link to this post

    Hi,

    i have an issue with maintaining state of template column textbox on paging in radgrid.
    I am storing the data in session and then on need datasource event trying to get the data again from session.
    But this does not help.
    Please help me its urgent issue.please refer code below-






    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadGrid ID="grChecklist1" runat="server"  AutoGenerateColumns="false"
                onneeddatasource="grChecklist1_NeedDataSource" 
            onpageindexchanged="grChecklist1_PageIndexChanged" >
       <MasterTableView  AllowPaging="true" AutoGenerateColumns="false"  PageSize="5"> 
        <Columns>
        <telerik:GridTemplateColumn DataField="Number" HeaderText="Number" Visible="true">
        <ItemTemplate>
             <asp:TextBox ID="txtNumber" runat="server" Text='<%#Bind("Number")%>'/>
        </ItemTemplate>
       </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn DataField="TaskDescription" HeaderText="TaskDescription" Visible="true">
        <ItemTemplate>
             <asp:TextBox ID="txtTaskDescription" runat="server" Text='<%#Bind("TaskDescription")%>' />
        </ItemTemplate>
       </telerik:GridTemplateColumn>
       </Columns>

    </MasterTableView>
    </telerik:RadGrid>
       

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    LoadDetails();
                }
            }

            private void LoadDetails()
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("Number",typeof(string));
                dt.Columns.Add("TaskDescription", typeof(string));
                dt.Rows.Add("1", "task1");
                dt.Rows.Add("2", "task2");
                dt.Rows.Add("3", "task3");
                dt.Rows.Add("4", "task4");
                dt.Rows.Add("5", "task5");
                dt.Rows.Add("6", "task6");
                dt.Rows.Add("7", "task7");
                //grChecklist.DataSource = dt;
               // grChecklist.DataBind();
                Session["dt"] = dt;

            }

            private void RefreshSessionState()
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("Number", typeof(string));
                dt.Columns.Add("TaskDescription", typeof(string));
                
                foreach (GridDataItem item in grChecklist1.Items)
                {
                  string number=(item.FindControl("txtNumber") as TextBox).Text;
                  string task = (item.FindControl("txtTaskDescription") as TextBox).Text;
                  dt.Rows.Add(number,task);
                }
                if (Session["dt"] != null)
                    Session.Remove("dt");
                Session["dt"] = dt;
            }

           

            protected void grChecklist1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
               // RefreshSessionState();
                grChecklist1.DataSource = (DataTable)Session["dt"];

            }

            protected void grChecklist1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
            {
                grChecklist1.AllowPaging = false;
                grChecklist1.Rebind();
               // RefreshSessionState();
               
                grChecklist1.CurrentPageIndex = e.NewPageIndex;
                grChecklist1.AllowPaging = true;
                grChecklist1.Rebind();
            }
        }
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 15 Nov 2014 in reply to S Link to this post

    Hi S,

    Please try with the below code snippet.

    ASPX
    <telerik:RadGrid ID="grChecklist1" runat="server" AutoGenerateColumns="false"
        OnNeedDataSource="grChecklist1_NeedDataSource"
        OnPageIndexChanged="grChecklist1_PageIndexChanged">
        <MasterTableView AllowPaging="true" AutoGenerateColumns="false" PageSize="5">
            <Columns>
                <telerik:GridTemplateColumn DataField="Number" HeaderText="Number" Visible="true">
                    <ItemTemplate>
                        <asp:TextBox ID="txtNumber" runat="server" Text='<%#Bind("Number")%>' />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="TaskDescription" HeaderText="TaskDescription" Visible="true">
                    <ItemTemplate>
                        <asp:TextBox ID="txtTaskDescription" runat="server" Text='<%#Bind("TaskDescription")%>' />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>


    ASPX.CS
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDetails();
        }
    }
    private void LoadDetails()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Number", typeof(string));
        dt.Columns.Add("TaskDescription", typeof(string));
        dt.Rows.Add("1", "task1");
        dt.Rows.Add("2", "task2");
        dt.Rows.Add("3", "task3");
        dt.Rows.Add("4", "task4");
        dt.Rows.Add("5", "task5");
        dt.Rows.Add("6", "task6");
        dt.Rows.Add("7", "task7");
        //grChecklist.DataSource = dt;
        // grChecklist.DataBind();
        Session["dt"] = dt;
     
    }
     
     
    protected void grChecklist1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        // RefreshSessionState();
        grChecklist1.DataSource = (DataTable)Session["dt"];
     
    }
     
    protected void grChecklist1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
    {
        DataTable dt = Session["dt"] as DataTable;
     
     
        int pagesize = 5;
        int currentpagesize = grChecklist1.CurrentPageIndex;
     
        for (int i = pagesize * currentpagesize; i < dt.Rows.Count; i++)
        {
            foreach (GridDataItem item in grChecklist1.MasterTableView.Items)
            {
                if (item.ItemIndex + (pagesize * currentpagesize) == i)
                {
                    dt.Rows[i]["Number"] = (item.FindControl("txtNumber") as TextBox).Text;
                    dt.Rows[i]["TaskDescription"] = (item.FindControl("txtTaskDescription") as TextBox).Text;
                }
            }
        }
     
     
    }


    Let me know if any concern.

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 17 Nov 2014 in reply to Jayesh Goyani Link to this post

    Hi Jayesh,

    Thanks, i solved my problem.

    I need one more help..when i deploy my code on server , some of the radtextboxes get distorted , size gets increased.
    This happens only in IE works perfectly in chrome.
    Can you please help?

    Thanks,
    SK
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 17 Nov 2014 in reply to S Link to this post

    Hi,

    Please add the height and width property on RadTextBox and check it.

    Sometimes it will apply browser's default style.

    Let me know if any concern.

    Thanks,
    Jayesh Goyani
  6. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 18 Nov 2014 in reply to Jayesh Goyani Link to this post

    thanks Jayesh..
    i had set width as 100% fro some of the radtextboxes and had also set the item  width in item style...
    removing textbox width solved the issue.

    Thanks for your timely help.

    Thanks,
    SK
  7. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 21 Nov 2014 in reply to Jayesh Goyani Link to this post

    Hi Jayesh,

    I have one more issue with radgrid..
    I have set enabled=false for radgrid. But i want paging to work on it.
    how do i enable paging when radgrid is disabled?

    Thanks,
    SK
  8. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 02 Dec 2014 in reply to Jayesh Goyani Link to this post

    hi Jayesh,

    i have one more issue , while sorting data in radgrid.
    this is more of a sql query , but thought if you could help.

    I have a varchar column- No it has values-1,1b,18,2,2a,11,1a,12,,18a,18b,22,222
    i want to sort these values in this order 1,1a,1b,2,2a,11,12,18,18a,18b,22,222
    Is there any way?
    Please help.




  9. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 27 Jan 2015 in reply to Jayesh Goyani Link to this post

    Hi Jayesh,

    I have a radgrid with a radcombobox. after page index changed for radgrid , when i change the selected index of the rad combobox , it gives me  javascript error-
    Error: Sys.WebForms.PageRequestManagerParserErrorException: The
    message received from the server could not be parsed.

    Please help.

    Thanks,
    SK

  10. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 27 Jan 2015 in reply to Jayesh Goyani Link to this post

    Hi Jayesh,

    I have a radgrid with a radcombobox (autopostback=true for this combobox). after page index changed for radgrid , when i change the selected index of the rad combobox , it gives me  javascript error-
    Error: Sys.WebForms.PageRequestManagerParserErrorException: The
    message received from the server could not be parsed.

    Please help.

    Thanks,
    SK
  11. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 27 Jan 2015 in reply to S Link to this post

    Hello,

    As per my knowledge this issue is related to UpdatePanel/RadAjaxManager than also could you please provide your code snippet so I will try to resolved your issue.

    Thanks,
    Jayesh Goyani
  12. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 28 Jan 2015 in reply to Jayesh Goyani Link to this post

    Hi Jayesh,

    Issue is resolved now. I had to add ValidateRequest="false"    in the aspx page and in web config for httpruntime section , had to add requestValidationMode="2.0" . This was related to some issue - System.Web.HttpRequestValidationException (0x80004005): A
    potentially dangerous Request.Form value was detected from the client.

    Thanks,
    SK
  13. Jaya
    Jaya avatar
    81 posts
    Member since:
    Mar 2011

    Posted 19 Mar 2015 in reply to Jayesh Goyani Link to this post

    Hi
    Jayesh Goyani

    I have Telerik Grid With one GridTemplateColumn for  <asp:TextBox here when i enter this textbox. I need total amount calculate and show the Footer column using Javascript or Jquery how will do this can you guide me most urgent.
  14. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 24 Mar 2015 in reply to Jaya Link to this post

    Hello Jaya,

    Please try with below code snippet.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TelerikWebApp1.WebForm1" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <title></title>
        <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
     
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script>
                function setfooter() {
                    var grid = $find("<%= RadGrid1.ClientID %>");
                    var sum = 0;
                    if (grid) {
                        var MasterTable = grid.get_masterTableView();
                        var Rows = MasterTable.get_dataItems();
                        for (var i = 0; i < Rows.length; i++) {
                            var row = Rows[i];
                            var txt1 = $(row.get_element()).find("input[id*='TextBox1']").get(0)
                            sum += parseInt(txt1.value);
                        }
                    }
                    $(".gridFooterLabel").get(0).innerHTML = sum;
     
                }
            </script>
        </telerik:RadCodeBlock>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
                <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound"
                    ShowFooter="true">
                    <MasterTableView AutoGenerateColumns="false">
                        <Columns>
                            <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name"></telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn>
                                <ItemTemplate>
                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("ID") %>' onchange="javascript:setfooter();"></asp:TextBox>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="Label1" runat="server" CssClass="gridFooterLabel"></asp:Label>
                                </FooterTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>
            </div>
        </form>
    </body>
    </html>

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    namespace TelerikWebApp1
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
     
            }
     
     
            protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            {
                dynamic data = new[] {
            new { ID = 1, Name ="Name1"},
            new { ID = 2, Name ="Name2"}
        };
                RadGrid1.DataSource = data;
            }
     
     
            double sum = 0;
            protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem dataItem = (GridDataItem)e.Item;
                    sum += double.Parse((dataItem.FindControl("TextBox1") as TextBox).Text);
                }
                else
                    if (e.Item is GridFooterItem)
                    {
                        GridFooterItem footer = (GridFooterItem)e.Item;
                        (footer.FindControl("Label1") as Label).Text = sum.ToString();
                    }
            }
        }
    }


    Let me know if any concern.

    Thanks,
    Jayesh Goyani
  15. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 22 Jun 2015 in reply to Jayesh Goyani Link to this post

    hi Jayesh,

     

    need urgent help.

    I have a radgrid which has  a usercontrol wherein i can attach multiple files as attachments for each row in radgrid.

    I also have add new row button which will add a new blank row to the grid.

    The issue is that when i add a new row , all the earlier rows which showed attachemnets in the usercontrol , they al;l are lost.I think this is ajax issue. but not able to trace. I also tried adding the usercontrol which is in radgrid for attachmnets to updatedcontrols in ajax , but no luck.Please help.

     

  16. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 24 Jun 2015 Link to this post

    Hello S,

    This is the default behavior of the asp.net. After postback uploaded is removed.

     As per my suggestion you have to use radaysncupload control it saves file immediately into temp folder. So after postback you can get the uploaded files from the temp folder.

    Let me know if any concern.

    Thanks, Jayesh Goyani

  17. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 24 Jun 2015 in reply to Jayesh Goyani Link to this post

    hi Jayesh, 

    am using radasynupload control itself in the usercontrol, it has this radasynupload control as well as a grid to display the files uploaded. but still its not working.

  18. S
    S avatar
    20 posts
    Member since:
    Nov 2014

    Posted 24 Jun 2015 in reply to Jayesh Goyani Link to this post

    Hi Jayesh, 

    please refer below scenario-

     I have a usercontrol for attachments. The usercontrol has a RadAsyncUpload and a grid to show the uploaded files.But when i use this usercontrol on my main page, and upload a file, it displays the first uploaded file immediately in the grid in usercontrol.But when i upload second time , the file gets uploaded but the UI is not refreshed and the second file is not shown in the grid.Please help.I have added ajax setting to update the usercontrol on my main page on click of the RadAsyncUpload button.  <telerik:AjaxSetting AjaxControlID="AsyncUpload1">
                    <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="usrAttachments" />
                 
                    </UpdatedControls>
                </telerik:AjaxSetting>

  19. Jaya
    Jaya avatar
    81 posts
    Member since:
    Mar 2011

    Posted 11 Feb in reply to Jayesh Goyani Link to this post

    Hi
     How to Implementation AutoCompleteBox with Image for Ex:
    My Control this but here i added this DataSourceID="SqlDataSource1"  but no need this i need fetch the data from database using c# and list object 
    can you fixed this
     <telerik:RadComboBox RenderMode="Lightweight" ID="RadComboBox1" runat="server" Width="400" Height="400px" 
                    EmptyMessage="Type an E-mail" DataSourceID="SqlDataSource1" DataTextField="ContactName"
                    OnItemDataBound="RadComboBox1_ItemDataBound">
                </telerik:RadComboBox>

    But My Need this
     In my AutocompleteBox shows like this -> multiple column with image then c# list object using webservices  for Data binding.

    EMPID   EMPNAME    EMPIMAGE
    100        NAME HERE  IMAGE HERE 

     how will do this any one fixed this
  20. Jaya
    Jaya avatar
    81 posts
    Member since:
    Mar 2011

    Posted 11 Feb in reply to Jayesh Goyani Link to this post

    Hi

    JEYESH

     

     How to Implementation AutoCompleteBox with Image for Ex:
    My Control this but here i added this DataSourceID="SqlDataSource1"  but no need this i need fetch the data from database using c# and list object 
    can you fixed this
     <telerik:RadComboBox RenderMode="Lightweight" ID="RadComboBox1" runat="server" Width="400" Height="400px" 
                    EmptyMessage="Type an E-mail" DataSourceID="SqlDataSource1" DataTextField="ContactName"
                    OnItemDataBound="RadComboBox1_ItemDataBound">
                </telerik:RadComboBox>

    But My Need this
     In my AutocompleteBox shows like this -> multiple column with image then c# list object using webservices  for Data binding.

    EMPID   EMPNAME    EMPIMAGE
    100        NAME HERE  IMAGE HERE 

     how will do this any one fixed this

  21. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 15 Feb Link to this post

    Hi Jaya,

    Please open a separate ticket/thread for every unrelated query you have. This way the information in the thread will be more consistent. Thus, it will be easier for you to search for information in your past threads.

    Also, if someone is facing similar issue they would be able to find the solution faster.


    Regards,
    Viktor Tachev
    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017