本文介绍了如何在ListView控件中使用下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello, i am retrieving 100 rows from database and binding in ListView to show. I have given PageSize="10" in Datapage control. so, it shows 10 by 10 in paging..
everything works fine. but i need to show 50 data on the page at a time. so, i used dropdown list to show it. but i do not know how to implement in this. i have posted my full coding. kindly help me where to apply dropdown list.
aspx page:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<style type="text/css">
.TableCSS
{
border-style:none;
background-color:Gray;
width:600px;
}
.TableHeader
{
background-color:Blue;
color:Maroon;
font-size:large;
font-family:Verdana;
}
.TableData
{
background-color:Black;
color:Silver;
font-family:Courier New;
font-size:medium;
font-weight:bold;
}
</style>
<div>
<h2 style="color:Navy; font-style:italic;"> ListView control Example : how to use Listview control</h2>
<hr width="550" align="left" color="PowderBlue" />
<div>
<asp:LinkButton ID="LIST_VIEW" Text="LIST" runat="server" ></asp:LinkButton>
<asp:DropDownList ID="ddlitemsize" runat="server" AutoPostBack="true" Font-Names="sans-Serif" Font-Size="11px" OnSelectedIndexChanged="itemsize_chaged">
<asp:ListItem Selected="True" Text="12" Value="12"></asp:ListItem>
<asp:ListItem Text="25" Value="25"></asp:ListItem>
<asp:ListItem Text="50" Value="50"></asp:ListItem>
<asp:ListItem Text="100" Value="100"></asp:ListItem>
</asp:DropDownList>
<asp:ListView ID="ListView1" OnPagePropertiesChanging="ListView1_PagePropertiesChanging"
runat="server"
>
<LayoutTemplate>
<table id="Table1" runat="server" class="TableCSS">
<tr runat="server" class="TableHeader">
<td runat="server">Product ID</td>
<td runat="server">Product Name</td>
</tr>
<tr id="ItemPlaceholder" runat="server">
</tr>
<tr><td><br /><br /></td></tr>
<tr id="Tr2" runat="server">
<td runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="TableData">
<td>
<asp:Label ID="Label1"
runat="server"
Text='<%# Eval("id") %>'
></asp:Label>
</td>
<td>
<asp:Label ID="Label2"
runat="server"
Text='<%# Eval("name") %>'
>
</asp:Label>
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>No data availbale</EmptyDataTemplate>
</asp:ListView>
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="10">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="true" />
</Fields>
</asp:DataPager>
</div>
</div>
</asp:Content>
aspx.cs (code behind)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Listview_app
{
public partial class _Default : System.Web.UI.Page
{
int image_lmt;
protected void Page_Load(object sender, EventArgs e)
{
List();
}
public void List(object sender, EventArgs e)
{
string sqlcon = ConfigurationManager.ConnectionStrings["constring"].ConnectionString.ToString();
SqlConnection con = new SqlConnection(sqlcon);
SqlCommand cmd = new SqlCommand("select top 100 * from Tablename", con);
SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adap.Fill(dt);
Session["pagingcon"] = dt;
ListView1.DataSource = dt.DefaultView;
ListView1.DataBind();
}
protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
list();
}
}
public void itemsize_chaged(object sender, EventArgs e)
{
// here i do not know what to do..
}
}
}
推荐答案
这篇关于如何在ListView控件中使用下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!