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

Nested RadListView With LinkButton Command Doesn't Refresh

5 Answers 76 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Chris Pautsch
Top achievements
Rank 1
Chris Pautsch asked on 01 May 2012, 11:41 PM
I have a RadListView nested within a RadListView. The inner RadListView has LinkButtons for copying/deleting/organizing the elements. When the LinkButtons are clicked, the events fire and I copy/delete/reorganize the data, but the page doesn't get updated. If I refresh the page or execute another command, the data is refreshed...but it's always one click behind. It's obviously an event sequence and after lots of searching it sounds like I need to use the AjaxManager. I've been wresting with this too long and need help.

ASPX
I included surrounding controls just in case this affected the solution. The issues I'm having are with rlvGroups,

<telerik:RadMultiPage ID="rmpTabs" runat="server" SelectedIndex="0" Width="100%">
    <telerik:RadPageView ID="rpv1" runat="server">
        Page title: <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
    </telerik:RadPageView>
    <telerik:RadPageView ID="rpv2" runat="server">
        <asp:Panel ID="pnlNotRelevant" runat="server">
        </asp:Panel>
    </telerik:RadPageView>
    <telerik:RadPageView ID="rpv4" runat="server">
        <asp:Panel ID="pnlItems" runat="server">
            <telerik:RadListView ID="rlvGroups" runat="server" OnItemDataBound="rlvGroups_ItemDataBound"
                Width="100%">
                <ItemTemplate>
                    <%# DataBinder.Eval(Container.DataItem, "Name")%>
                    <br />
                    <telerik:RadListView ID="rlvItems" runat="server" OnItemDataBound="rlvItems_ItemDataBound"
                        Width="100%">
                        <ItemTemplate>
                            <%# DataBinder.Eval(Container.DataItem, "Title")%>
                            <asp:LinkButton ID="lbUp" runat="server" OnCommand="lbUp_Command"><img src="arrow-up.png" /></asp:LinkButton>
                            <asp:LinkButton ID="lbDown" runat="server" OnCommand="lbDown_Command"><img src="arrow-down.png" /></asp:LinkButton>
                            <asp:LinkButton ID="lbEdit" runat="server" OnCommand="lbEdit_Command"><img src="edit.jpg" /></asp:LinkButton>
                            <asp:LinkButton ID="lbCopy" runat="server" OnCommand="lbCopy_Command"><img src="copy.jpg" /></asp:LinkButton>
                            <asp:LinkButton ID="lbDelete" runat="server" OnCommand="lbDelete_Command"><img src="delete.png" /></asp:LinkButton>
                        </ItemTemplate>
                    </telerik:RadListView>
                    <asp:LinkButton ID="lbAddPage" runat="server" Text="Add Page" OnCommand="lbAddPage_Command" />
                    <br />
                    <br />
                </ItemTemplate>
            </telerik:RadListView>
            <asp:LinkButton ID="lbAddGroup" runat="server" Text="Add Group" OnCommand="lbAddGroup_Command" />
        </asp:Panel>
    </telerik:RadPageView>
</telerik:RadMultiPage>

C#
Data is loaded from custom classes:
private void RefreshGroupsItems()
{
    rlvGroups.DataSource = tab.ViewX.Groups.Group;
    rlvGroups.DataBind();
}

protected void rlvGroups_ItemDataBound(object sender, RadListViewItemEventArgs e)
{
    if (e.Item.ItemType == RadListViewItemType.DataItem || e.Item.ItemType == RadListViewItemType.AlternatingItem)
    {
        //Get datarow
        Group group = (Group)(((RadListViewDataItem)e.Item).DataItem);

        //Find controls
        RadListView rlvItems = (RadListView)e.Item.FindControl("rlvItems");
        LinkButton lbAddPage = (LinkButton)e.Item.FindControl("lbAddPage");

        //Populate controls
        List<ListItem> data = DataHelpers.BuildListItem(group);
        rlvItems.DataSource = data;
        rlvItems.DataBind();
        lbAddPage.CommandArgument = group.ID.ToString();
    }
}

protected void rlvItems_ItemDataBound(object sender, RadListViewItemEventArgs e)
{
    if (e.Item.ItemType == RadListViewItemType.DataItem || e.Item.ItemType == RadListViewItemType.AlternatingItem)
    {
        //Get datarow
        ListItem item = (ListItem)(((RadListViewDataItem)e.Item).DataItem);

        //Find controls
        LinkButton lbUp = (LinkButton)e.Item.FindControl("lbUp");
        LinkButton lbDown = (LinkButton)e.Item.FindControl("lbDown");
        LinkButton lbEdit = (LinkButton)e.Item.FindControl("lbEdit");
        LinkButton lbCopy = (LinkButton)e.Item.FindControl("lbCopy");
        LinkButton lbDelete = (LinkButton)e.Item.FindControl("lbDelete");

        //Populate controls
        lbUp.CommandArgument = item.ID.ToString();
        lbDown.CommandArgument = item.ID.ToString();
        lbEdit.CommandArgument = item.ID.ToString();
        lbCopy.CommandArgument = item.ID.ToString();
        lbDelete.CommandArgument = item.ID.ToString();
    }
}

Please help!

5 Answers, 1 is accepted

Sort by
0
Chris Pautsch
Top achievements
Rank 1
answered on 02 May 2012, 01:30 AM
I did more research...do I need to get rid of the simple databinding and implement advanced data binding with the "NeedDataSource" method? If so, will that do it or do I need to add AjaxManager entries? And finally, would you recommend another approach with different controls? This is very close...just a refreshing issue.
0
Chris Pautsch
Top achievements
Rank 1
answered on 02 May 2012, 03:56 PM
I changed the outer ListView to:
<telerik:RadListView ID="rlvGroups" runat="server" OnNeedDataSource="rlvGroups_NeedDataSource" OnItemDataBound="rlvGroups_ItemDataBound">

and added the event. The page renders as it did before...no issues...but when I execute a command (click a linkbutton in the inner ListView), the page still doesn't refresh. I am calling "rlvGroups.Rebind();" after the command is processed.

Any ideas? Do I need to use the AjaxManager?
0
Andrey
Telerik team
answered on 07 May 2012, 07:47 AM
Hi,

Most probably the behavior you are experiencing is caused by databinding problem. In this case I do not think that RadAjaxManager will help, it is used to Ajax-ify(partially update control on the page) a solution which is already working as expected.

Could you post your entire code-behind along with the rest of the mark-up code? Thus I will better understand your scenario.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Chris Pautsch
Top achievements
Rank 1
answered on 07 May 2012, 02:27 PM
I should have replied last Friday...I figured it out.
The problem was that the ReBind() method DOES NOT always call NeedDataSource!
In order to get it to call, I had to do this:

rlvGroups.DataSource = null;
rlvGroups.Rebind();

Is this a bug? Working as designed?
0
Andrey
Telerik team
answered on 08 May 2012, 03:23 PM
Hi,

Yes, that was my next suggestion.

This is an expected behavior, RadGrid by itself decides when to fire the NeedDataSource event, this is true because RadGrid cache its datasource for performance optimizations. There is no need to fetch the data from the server over and over again if there is no change in the data.

And as you found out in order to force it to fire the event you should set the datasource as null outside of the event.

I hope this helps.

Greetings,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ListView
Asked by
Chris Pautsch
Top achievements
Rank 1
Answers by
Chris Pautsch
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or