Jay Patel

Jay Patel

  • NA
  • 10
  • 676

I want to get my lisview scroll to the selected item and cha

Feb 22 2017 11:33 PM

I want to get my listview to scroll to the user selected index and change its appearance. I tired to get this in many ways but nothing worked for me.

When I select any item from listview I am able to get the data and index of selected item but the SelectedTemplate apply on previous Index. Don't know how ?

for eg: By Default I selected index "0", so when I select index "3" the SelectedTemplate applies on index "0" and when I select index "5" the SelectedTemplate applies on index "3".

Codes are below, hope to get some help.

Web Form 
  1. <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">  
  2.   
  3.         <ContentTemplate>  
  4.             <div class="VDOContainer raw">  
  5.                 <div class="vdoname" id="area" runat="server">  
  6.                     <asp:Label ID="VDOName" runat="server" CssClass="vdofonthead" Text="Video Name"></asp:Label>  
  7.                 </div>  
  8.   
  9.                 <div class="boxleft col-lg-8 col-md-8 col-sm-12">  
  10.                     <asp:Literal ID="lblvedio" runat="server"></asp:Literal>  
  11.                     <ul class="raw like-section">  
  12.                         <li class="col-md-6 like-btn">  
  13.                             <asp:Button ID="btn_Like" runat="server" Text="Like" CssClass="btn btn-outline btn-lg"></asp:Button>  
  14.                             <div class="btn btn-lg" style="cursor:default;">  
  15.                                 <img class="vlike" src="img/like.png" alt="like image" />  
  16.                                 <asp:Label ID="lblLike" runat="server"></asp:Label>  
  17.                             </div>  
  18.                             <div class="btn btn-lg" style="cursor:default;">  
  19.                                 <img class="vlike" src="img/like.png" alt="like image" />  
  20.                                 <asp:Label ID="lblView" runat="server"></asp:Label>  
  21.                                 Views  
  22.                             </div>  
  23.                         </li>  
  24.                     </ul>  
  25.                     <div class="vdoname" id="Div1" runat="server">  
  26.                         <asp:Label ID="VDODesc" runat="server" CssClass="vdofonthead" Text="Video Description"></asp:Label>  
  27.                     </div>  
  28.                 </div>  
  29.   
  30.                 <div class="boxright col-lg-4 col-md-4 col-sm-12">  
  31.                     <asp:ListView runat="server" ID="listviedo"  
  32.                         OnSelectedIndexChanged="listviedo_SelectedIndexChanged"  
  33.                         OnSelectedIndexChanging="listviedo_SelectedIndexChanging"  
  34.                         SelectedIndex="0" FullRowSelect="true"   
  35.                         DataKeyNames="VID" ClientIDMode="AutoID">  
  36.                         <ItemTemplate>  
  37.                             <asp:Panel runat="server" ID="selected_panel" >  
  38.                                 <div class="vdofont">  
  39.                                     <asp:LinkButton runat="server" ID="linkbtn" CommandName="Select" CommandArgument='<%# Eval("VID") %>'>  
  40.                                         <asp:Label ID="lblname" runat="server" Text='<%# Eval("VideoName")%>'></asp:Label>  
  41.                                         <asp:Label ID="lblid" runat="server" Visible="false" Text='<%# Eval("VID")%>'></asp:Label>  
  42.                                     </asp:LinkButton>  
  43.                                 </div>  
  44.                             </asp:Panel>  
  45.                         </ItemTemplate>  
  46.                         <SelectedItemTemplate>  
  47.                             <asp:Panel runat="server" ID="selected_panel" CssClass="boxright_active" BackColor="SkyBlue">   
  48.                                 <div class="vdofont boxright_active">  
  49.                                     <asp:LinkButton runat="server" ID="linkbtn" CommandName="Select" CommandArgument='<%# Eval("VID") %>'>  
  50.                                         <asp:Label ID="lblname" runat="server" Text='<%# Eval("VideoName")%>'></asp:Label>  
  51.                                         <asp:Label ID="lblid" runat="server" Visible="false" Text='<%# Eval("VID")%>'></asp:Label>  
  52.                                     </asp:LinkButton>  
  53.                                 </div>  
  54.                             </asp:Panel>  
  55.                         </SelectedItemTemplate>  
  56.                     </asp:ListView>  
  57.                 </div>  
  58.             </div>  
  59.   
  60.         </ContentTemplate>  
  61.         <Triggers>  
  62.             <asp:AsyncPostBackTrigger ControlID="listviedo" EventName="SelectedIndexChanged" />  
  63.             <asp:AsyncPostBackTrigger ControlID="listviedo" EventName="SelectedIndexChanging" />  
  64.             <asp:AsyncPostBackTrigger ControlID="listviedo" EventName="ItemCommand" />  
  65.         </Triggers>  
  66.     </asp:UpdatePanel>  
 
C# Code Behind
  1. protected void listviedo_ItemCommand(object sender, ListViewCommandEventArgs e)  
  2.     {  
  3.         Literal lblvedio = (Literal)e.Item.FindControl("lblvedio");  
  4.         Label lblname = (Label)e.Item.FindControl("lblname");  
  5.         if (e.CommandName == "Select")  
  6.         {  
  7.             int ID = Convert.ToInt32(e.CommandArgument);  
  8.             Database.Tbl obj = DB.Tbl.Single(p => p.VID == ID);  
  9.             if (obj.IsUrl == false)  
  10.             {  
  11.                 string Link = "<iframe></iframe>";  
  12.             }  
  13.             else  
  14.             {  
  15.                 string Link = "<iframe></iframe>";  
  16.             }  
  17.         }  
  18.         if (e.CommandName == "Resume")  
  19.         {  
  20.             int ID = Convert.ToInt32(e.CommandArgument);  
  21.             Database.Tbl objcar = DB.Tbl.Single(p => p.VID == ID);   
  22.         }  
  23.     }  
  24.     protected void listviedo_ItemDataBound(object sender, ListViewItemEventArgs e)  
  25.     {  
  26.         Label lblid = (Label)e.Item.FindControl("lblid");  
  27.         LinkButton linkresuume = (LinkButton)e.Item.FindControl("linkresuume");  
  28.         int ID = Convert.ToInt32(lblid.Text);  
  29.         Database.Tbl objcar = DB.Tbl.Single(p => p.VID == ID);              
  30.     }  
  31.     protected void listviedo_SelectedIndexChanged(object sender, EventArgs e)  
  32.     {  
  33.         if (Session["USER"] == null)  
  34.         {  
  35.             Response.Redirect("Login");  
  36.         }  
  37.         else  
  38.         {  
  39.                             if (listviedo.SelectedIndex >= 0)  
  40.             {  
  41.                 int id1 = Convert.ToInt32(listviedo.SelectedValue.ToString());  
  42.                 lblvedio.Text = getvalue(id1);  
  43.                 VDOName.Text = getName(id1);  
  44.                 VDODesc.Text = getDesc(id1);  
  45.                 lblView.Text = getView(id1).ToString();  
  46.                 lblLike.Text = getLike(id1).ToString();  
  47.             }  
  48.         }  
  49.     }  
  50.   
  51.     protected void listviedo_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)  
  52.     {   
  53.         this.listviedo.SelectedIndex = e.NewSelectedIndex;   
  54.     }  
CSS 
  1. .boxright {  
  2.     floatleft;  
  3.     height890px;  
  4.     margin0 auto;  
  5.     overflowauto;  
  6.     padding10px 10px 10px 10px;  
  7.     background-color: rgba(002550.12);  
  8. }  
  9.   
  10. .boxright div:hover {  
  11.     transform: scale(1.01);  
  12.     box-shadow: 1px 1px 5px 0px #777;  
  13.     border-radius:5px;  
  14. }  
  15.   
  16. .boxright_active {  
  17.     transform: scale(1.01);  
  18.     box-shadow: 1px 1px 10px 0px #777;  
  19.     border-radius:5px;  
  20. }  
  21.   
  22. .boxright div:active {  
  23.     transform: scale(1.01);  
  24.     box-shadow: 1px 1px 10px 0px #777;  
  25.     border-radius:5px;  
  26. }  
  27.   
  28. .boxleft {  
  29.     floatleft;  
  30.     margin0 auto;  
  31.     padding15px;  
  32.     overflowhidden;  
  33. }  
 

Answers (4)