Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ListView > Dynamically setting LinkButton within Listview

Not answered Dynamically setting LinkButton within Listview

Feed from this thread
  • Adam avatar

    Posted on Nov 4, 2011 (permalink)

    I have a RadListView and within the listview I have an asp.net linkbutton. I want to dynamically set the linkbutton's PostBackUrl. I can achieve this if I find the linkbutton control in the listview's ItemDataBound event. But by doing this when I end up clicking on the linkbutton the listview ItemCommand event is not being fired. I need the itemCommand even to be fired so I can take the datakeyvalue of the item clicked and set it into a session variable to pass to teh postbackurl page of the link button.

    <telerik:RadListView ID="lstVwWebpageList" runat="server" EnableViewState="true" ItemPlaceholderID="webpageContainer" AllowPaging="true" DataKeyNames="id" Skin="WebBlue" OnItemDataBound="lstVwWebpageList_ItemDataBound" OnPageIndexChanged="lstVwWebpageList_PageChange" Width="607px" OnItemCommand="lstVwWebpageList_ItemCommand">
        <LayoutTemplate>
            <table cellpadding="0" cellspacing="0">
                <tr>
                <td>
                    <asp:PlaceHolder ID="webpageContainer" runat="server" />
                </td>
                </tr>
                <tr>
                <td>
                <telerik:RadDataPager ID="Pager" runat="server" PagedControlID="lstVwWebpageList" PageSize="50" Skin="WebBlue">
                    <Fields>
                        <telerik:RadDataPagerButtonField FieldType="FirstPrev" />
                        <telerik:RadDataPagerButtonField FieldType="Numeric" />
                        <telerik:RadDataPagerButtonField FieldType="NextLast" />
                    </Fields>
                </telerik:RadDataPager>
                </td>
                </tr>
            </table>
        </LayoutTemplate>
         
        <ItemTemplate>
            <fieldset style="float: left; width: 300px;">
                <table cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            <table cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="width: 25%;">
                                        <b>Name:</b>
                                    </td>
                                    <td style="width: 75%;">
                                        <asp:Label ID="lblName" runat="server" Text='<%# Eval("name") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 25%;">
                                        <b>Page:</b>
                                    </td>
                                    <td style="width: 75%;">
                                        <asp:LinkButton ID="pagenameLink" runat="server" CommandName="LinkClicked" Text='<%# Eval("pagename") %>'></asp:LinkButton>                                   
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </fieldset>
        </ItemTemplate>
    </telerik:RadListView>


    protected void lstVwWebpageList_ItemDataBound(object sender, RadListViewItemEventArgs e)
       {
           LinkButton link = (LinkButton)e.Item.FindControl("pagenameLink");
           Label lblname = (Label)e.Item.FindControl("lblName");
     
           link.PostBackUrl = "EditWebpage.aspx?name=" + lblname.Text + "&page=" + link.Text;
     
           //RadListViewDataItem item = (RadListViewDataItem)e.Item;
           //Session["linkID"] = item.DataItem;// Convert.ToInt32(item.OwnerListView.DataKeyValues[item.DisplayIndex]["id"]);
       }
     
       protected void lstVwWebpageList_ItemCommand(object sender, RadListViewCommandEventArgs e)
       {
           if (e.CommandName == "LinkClicked")
           {
               RadListViewDataItem item = (RadListViewDataItem)e.ListViewItem;
               Session["linkID"] = item.DataItem;// Convert.ToInt32(item.OwnerListView.DataKeyValues[item.DisplayIndex]["id"]);
           }
       }

    Reply

  • Tsvetoslav Tsvetoslav admin's avatar

    Posted on Nov 9, 2011 (permalink)

    Hi Adam,

    The Item command event is not fired because you are making a redirect to a different page. Just get the data key value in the ItemDataBound event and set it as a query string parameter in the url of the page which the list view is redirecting to.

    Hope it helps.

    All the best, Tsvetoslav
    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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ListView > Dynamically setting LinkButton within Listview
Related resources for "Dynamically setting LinkButton within Listview"

ASP.NET ListView Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]