RadGrid rebind in UserControls

5 posts, 0 answers
  1. Edward Deutscher
    Edward Deutscher avatar
    3 posts
    Member since:
    Nov 2007

    Posted 20 Oct 2010 Link to this post

    I have read through a number of posts and articles today and am still a bit unclear on how to solve a particular rebind issue we are seeing. Any help would be greatly appreciated.

    ASPX Page (Default.aspx)
        -> RadTabString
        -> RadMultiPageView
            -> UserControl
                -> RadPanelBar
                    -> RadGrid

    The hierarchy above outlnes where my grid is in the page. Basically we are mimicing the same functionality found in this demo: 
    Using RadWindow to Edit a Grid Row

    The main difference is that our grid is not on the same page like the demo but embedded in a usercontrol and also within a RadPanel that allows us to collapse the multiple grids that are on that control.

    As with some other posters, we are seeing the issue of the RadGrid not refreshing when you call Rebind within the RadAjaxManager1_AjaxRequest call.

    We do see the _NeedDataSource call being made and the DataSource being set to the update data object, the control itself just won't redraw.

    Is there an efficient way to make the grid refresh in this scenario?

    Thanks





  2. Aaron
    Aaron avatar
    9 posts
    Member since:
    Jun 2009

    Posted 21 Oct 2010 Link to this post

    Edward,

    In this case you should'n have any problem doing the rebind, whether the grid is in the page or the user control, for example, if you need just to handle the rebind, this is what i do

    as an example, this is one of my grids, don't pay attention to all the code

    <telerik:RadGrid ID="rgLines" runat="server" 
        AllowPaging="True" AllowSorting="True"
        GridLines="None" AutoGenerateColumns="False"
        AllowAutomaticDeletes="True"
        onitemcommand="rgLines_ItemCommand"
        Skin="Black" onprerender="rgLines_PreRender"
              onselectedindexchanged="rgLines_SelectedIndexChanged" >
            <PagerStyle AlwaysVisible="True" />
          <MasterTableView EditMode="PopUp" InsertItemPageIndexAction="ShowItemOnFirstPage"
          CommandItemDisplay="Top">
            <CommandItemSettings AddNewRecordText="Add New Line" />
            <Columns>
              <telerik:GridBoundColumn DataField="Id" HeaderText="Line"
              UniqueName="LineColumn">
                <HeaderStyle Width="100px" />
              </telerik:GridBoundColumn>
              <telerik:GridBoundColumn DataField="Identifier" HeaderText="Identifier"
              UniqueName="IdentifierColumn">
                <HeaderStyle Width="100px" />
              </telerik:GridBoundColumn>
              <telerik:GridBoundColumn DataField="Plant" HeaderText="Plant"
              UniqueName="PlantColumn">
                <HeaderStyle Width="100px" />
              </telerik:GridBoundColumn>
              <telerik:GridButtonColumn ButtonType="ImageButton" HeaderText="Edit"
              UniqueName="EditColumn" CommandName="Edit" ImageUrl="~/Resources/Icon_edit.gif">
                <HeaderStyle Width="50px" />
              </telerik:GridButtonColumn>
              <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"
              HeaderText="Delete" UniqueName="DeleteColumn"
              ConfirmText="Do you want to delete this row?" ConfirmTitle="Warning" ImageUrl="~/Resources/Icon_delete.gif">
                <HeaderStyle Width="50px" />
              </telerik:GridButtonColumn>
            </Columns>
            <EditFormSettings EditFormType="WebUserControl"
            UserControlName="~/UserControls/EditLines.ascx">
              <EditColumn ButtonType="PushButton">
              </EditColumn>
              <PopUpSettings Modal="True" Height="300px" />
            </EditFormSettings>
              <PagerStyle AlwaysVisible="True" />
          </MasterTableView>
          <ClientSettings EnableRowHoverStyle="True" EnablePostBackOnRowClick="True">
            <ClientEvents OnPopUpShowing="PopUpShowing" />
            <Selecting AllowRowSelect="True" />
          </ClientSettings>
        </telerik:RadGrid>

    but the important part is this:

    onitemcommand="rgLines_ItemCommand"

    that event triggers whenever you want to do something, wether it's an update, delete, refresh, page index change, and this is how i handle the rebind

    protected void rgLines_ItemCommand(object source, GridCommandEventArgs e)
            {
                switch (e.CommandName)
                {
                    case "InitInsert":
                        //Change target user control
                        rgLines.MasterTableView.EditFormSettings.UserControlName = "~/UserControls/AddLines.ascx";
                        break;
                    case "Edit":
                        //Change target user control
                        rgLines.MasterTableView.EditFormSettings.UserControlName = "~/UserControls/EditLines.ascx";
                        break;
                    case "Delete":
                        //Delete event custom code
                        break;
                    case "Insert":
                        //Insert custom code                  
                        break;
                    case "Update":
                        //Update custom code
                        break;
                }
    ObtenerLineas();
            }

    as you can see, i evaluate the command name, and do something different in every importanta case for me, and at the end, i use the "ObtenerLineas();" function, to bind my grid
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Edward Deutscher
    Edward Deutscher avatar
    3 posts
    Member since:
    Nov 2007

    Posted 26 Oct 2010 Link to this post

    Thanks for the reply Aaron. My issue is that when I call my equivalent of your ObtenerLineas(), it steps through the bind code and thinks it rebinds the grid but the grid does not visibly update.

  5. Aaron
    Aaron avatar
    9 posts
    Member since:
    Jun 2009

    Posted 26 Oct 2010 Link to this post

    Would you mind to post your code, project, or at least the way that you are doing your databinding???
  6. Gajanan
    Gajanan  avatar
    49 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    hi ,
    in my case also was faced same problem,in first time it was not updating the grid with updated records but if i refresh the page or if i do the post back the it was updated the grid with updated records. even i was also using the AjaxRequest for that but after  i used Javascript function in that i am Explicitly Rebinding the grid then it is working fine.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017