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

RadGrid rebind in UserControls

4 Answers 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Edward Deutscher
Top achievements
Rank 1
Edward Deutscher asked on 20 Oct 2010, 10:08 PM
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





4 Answers, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 2
answered on 21 Oct 2010, 09:32 PM
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
0
Edward Deutscher
Top achievements
Rank 1
answered on 26 Oct 2010, 04:23 PM
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.

0
Aaron
Top achievements
Rank 2
answered on 26 Oct 2010, 05:19 PM
Would you mind to post your code, project, or at least the way that you are doing your databinding???
0
Gajanan
Top achievements
Rank 2
answered on 27 Oct 2010, 05:58 AM
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.
Tags
Grid
Asked by
Edward Deutscher
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 2
Edward Deutscher
Top achievements
Rank 1
Gajanan
Top achievements
Rank 2
Share this question
or