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

Link button is not working in listview

1 Answer 214 Views
ListView
This is a migrated thread and some comments may be shown as answers.
john
Top achievements
Rank 1
john asked on 11 Jun 2012, 05:43 AM
Hi,


    I used a Link button in listview itemtemplate.I need to redirect to a page in a new window.
But, I unable to find the solution.. It does not redirect to..


My code is here...
 
<telerik:RadAjaxPanel ID="rAjaxPnlForumsCategory" runat="server" LoadingPanelID="rAjaxLoadingPnlForumsCategory">
    <div style="border-top:1px solid #828282; border-bottom:1px solid #828282;">
 
        <telerik:RadListView ID="rlstviewReply" runat="server" Width="100%"
                             DataKeyNames="ForumPostReplyID"
                             OnNeedDataSource="rlstviewReply_NeedDataSource"
                             OnItemDataBound="rlstviewReply_ItemDataBound">
            <ItemTemplate >
                <table width="100%">
                    <tr>
                        <td>
                            Replied by
                            <asp:LinkButton ID="lnkbtnCandidateName" runat="server" OnCommand="lnkbtnCandidateName_Command" Enabled="false"  CssClass="_TextBoldSubCategory"></asp:LinkButton>
                          <span> On <asp:Label ID="lblCreatedOn" runat="server" Text=""></asp:Label></span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div id="divReply" runat="server" class="_PaddingTop5 _PaddingBottom5"><%# Eval("Reply") %></div>
                        </td>
                    </tr><tr><td id="Td1" runat="server" visible='<%# (Container.DataItemIndex + 1).ToString() != hidCount.Value  %>' align="center" class="DottedLineBottom2" style="text-align:center;"></td></tr>
                        
                </table>
            </ItemTemplate>
        </telerik:RadListView>
    </div>
  
    <div class="_PaddingTop20">
        Post your reply
        <div class="_PaddingTop20">    
        <telerik:RadEditor runat="server" Skin="Telerik" ToolsFile="~/Forums/RadEditorTools.xml"  ContentAreaCssFile="~/Styles/Editorstyle.css"
                           ID="radeditorReply" Width="100%">
        </telerik:RadEditor>
        <asp:RequiredFieldValidator CssClass="ErrorMessage" ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="radeditorReply" ValidationGroup="reply"></asp:RequiredFieldValidator>
        </div>
    </div>
    <div class="_PaddingTop5" style="text-align :center;">
        <telerik:RadButton ID="btnSubmit" runat="server" Text="SUBMIT" onclick="btnSubmit_Click" ValidationGroup="reply">
        </telerik:RadButton>
    </div>
    <div> </div>
</telerik:RadAjaxPanel>
<asp:HiddenField ID="hidCount" runat="server" />
 
 
        protected void rlstviewReply_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
        {
            try
            {
                if (!(e.Item is RadListViewDataItem))
                {
                    return;
                }
 
                if (e.Item is RadListViewItem)
                {
                    RadListViewDataItem rlvItem = (RadListViewDataItem)e.Item;
 
                    LinkButton lnkbtnCandidateName = (LinkButton)rlvItem.FindControl("lnkbtnCandidateName");
                    Label lblCreatedOn = (Label)rlvItem.FindControl("lblCreatedOn");
 
                    ForumPostReplies forumpostsreply = (ForumPostReplies)rlvItem.DataItem;
                    if (forumpostsreply == null)
                    {
                        return;
                    }
 
                    lnkbtnCandidateName.Text = string.Format("{0}", forumpostsreply.Users.UserName);
                    lblCreatedOn.Text = forumpostsreply.CreatedOn.ToString("g");
 
                    if (SessionHandler.User.UserTypeID == (int)FrameworkConstants.USER_TYPE.Employer)
                    {
                        lnkbtnCandidateName.Enabled = true;
                        lnkbtnCandidateName.CommandArgument = forumpostsreply.Users.UserID.ToString();
                        lnkbtnCandidateName.Attributes.Add("OnClick", " window.location.href =" + FrameworkConstants.PROJECT_PAGES.CANDIDATE_PROFILE.Description() + ");");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogging.AddErrorLog(ex);
            }
        }
 
        protected void lnkbtnCandidateName_Command(object sender, CommandEventArgs e)
        {
            try
            {
                if (e.CommandArgument == null)
                {
                    return;
                }
 
                long userID = 0;
                if (long.TryParse(e.CommandArgument.ToString(), out userID))
                {
                    Session[FrameworkConstants.SESSION_VARIABLES.CANDIDATEID.ToString()] = userID;
                }
            }
            catch (Exception ex)
            {
                ErrorLogging.AddErrorLog(ex);
            }
        }


Thank you in advance...

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 13 Jun 2012, 07:00 PM
John,

This may have something to do with properly ajaxifying the link button with your rAjaxPnlForumsCategory.

Take a look at the solution proposed by Telerik Admin: Iana  in the  RadListView - Ajax Problem - ItemCommand Event forum thread.

Also, there is an online demo that may provide some insights: ListView/Image Gallery.

In this demo, when the RadBinaryImage control that is within a RadListView ItemTemplate gets clicked, it opens the image in a popup window. This is somewhat similar to your requirement, if I understand it correctly.

I hope that this helps.
Tags
ListView
Asked by
john
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or