如何在listview asp.net中将焦点或页面位置设置为特定行

时间:2015-01-16 09:35:40

标签: asp.net listviewitem

我想将重点放在listview中的特定行上,页面位置应该在该行上。有什么建议请帮帮我

我的代码是

ASPX

<asp:ListView ID="lstanswer" runat="server" OnItemCommand="lstanswer_ItemCommand1">
    <ItemTemplate>
        <div class="panel-body"  style='<%# String.Format("background-color:{0}", Eval("colors")) %>' >
            <ul class="chat">
                <li class="left">
                    <div class="row" >
                        <div class="col-lg-1">
                                <img src="images/profiledummypic.jpg" height="50" width="60px" alt="PostedBy" />
                        </div>
                        <div class="col-lg-11">
                            <asp:HiddenField ID="hdnAnswerId" runat="server" Value='<%#Eval("AID") %>' />
                          <%#Eval("Colors") %>
                            <p class="clearfix" style="padding-left:5px">
                                <asp:Literal ID="ltrAnswer" runat="server" Text='<%#Eval("Answer") %>'></asp:Literal></p>
                        </div>
                    </div>
                </li>
                <li class="left clearfix">
                    <div class="chat-body clearfix">
                        <div class="header">
                            <small class="text-muted">
                                <div class="pull-left">
                                    <%--<asp:Label ID="lblYouliked" runat="server" Text="You Like this" Visible='<%#(Eval("Rate").ToString())=="1"%>'></asp:Label>--%>
                                    <asp:ImageButton CommandName="Like" CommandArgument='<%#Container.DataItemIndex%>'
                                        ID="imglike" runat="server" Height="30px" Width="80px" ImageUrl='<%#(Eval("Rate").ToString())=="0"?"~/images/likebutton.png":"~/images/youlikethis.png"%>'
                                        Enabled='<%#(Eval("Rate").ToString())=="0"%>' ToolTip='<%#(Eval("Rate").ToString())=="1"?"You Like this":"Click to Like" %>' />
                                    <asp:Label ID="lblviews" runat="server" Text='<%# String.Format("{0} Likes", Eval("TotalRatting")) %>'></asp:Label>
                                </div>
                                <div class="pull-right">
                                    Answered By<a href="#"><i class="fa fa-user fa-fw"></i><%#Eval("AnsUserName") %></a> <a href="#"><i class="fa fa-user fa-fw"></i>Follow</a><br />
                                    Answered on<a href="#"><i class="fa fa-user fa-fw"></i><%# Convert.ToDateTime(Eval("AnsweredOn")).ToString("dd/MM/yyyy")%></a>
                                </div>
                            </small>
                        </div>
                        </di>
                        <p>
                        </p>
                    </div>
                </li>
            </ul>
        </div>
    </ItemTemplate>
</asp:ListView>

并且在 C#

lstanswer.Items[6].Focus();
lstanswer.Items[0].Focus();

但页面不会滚动或关注该行

0 个答案:

没有答案