Yazı Font Küçült Yazı Font Büyült

DetailsView da Sayfalama

 

Merhaba arkadaşlar, bu makalemizde DetailsView nesnesinde DropDownList i kullanarak sayfalama işlemi yapacağız. DetailsView ın AllowPaging özelliğini True yapın.

Daha sonra  DetailsView ın <PagerTemplate> </PagerTemplate> kısmına DropDownList nesnesi ile Button ekleyin.

 

Resim1

Şekil 1

 

Resim2

Şekil 2

 

Default.aspx.cs

 

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Web;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

 

publicpartialclass_Default : System.Web.UI.Page

{

 

protectedvoiddtlProducts_DataBound(objectsender, EventArgs e)

{

DropDownListddlist = (DropDownList)DetailsView1.BottomPagerRow.Cells[0].FindControl("DropDownList1");

for (int i = 0; i <= DetailsView1.PageCount - 1; i++)

{

ListItemitem = newListItem(string.Format("Sayfa {0}", i + 1), i.ToString());

if (DetailsView1.PageIndex == i)

{

item.Selected = true;

}

ddlist.Items.Add(item);

}

}

 

protectedvoidbtnTıkla_Click(objectsender, EventArgs e)

{

DropDownListddlist = (DropDownList)DetailsView1.BottomPagerRow.Cells[0].FindControl("DropDownList1");

        DetailsView1.PageIndex = Int32.Parse(ddlist.SelectedValue);

}

 

 

}

 

Default.aspx

 

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>

 

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title></title>

</head>

<body>

<formid="form1"runat="server">

<div>

 

<asp:DetailsViewID="DetailsView1"runat="server"AllowPaging="True"

AutoGenerateRows="False"DataKeyNames="id"DataSourceID="AccessDataSource1"

Height="50px"OnDataBound="dtlProducts_DataBound"

Width="125px">

<Fields>

<asp:BoundFieldDataField="id"HeaderText="id"InsertVisible="False"

ReadOnly="True"SortExpression="id"/>

<asp:BoundFieldDataField="BASLIK"HeaderText="BASLIK"

SortExpression="BASLIK"/>

<asp:BoundFieldDataField="HIT"HeaderText="HIT"SortExpression="HIT"/>

</Fields>

<PagerTemplate>

<asp:DropDownListID="DropDownList1"runat="server">

</asp:DropDownList>

<asp:ButtonID="btnPage"runat="server"Text="Git"OnClick="btnTıkla_Click"/>

</PagerTemplate>

</asp:DetailsView>

<br/>

 

</div>

<asp:AccessDataSourceID="AccessDataSource1"runat="server"

DataFile="~/App_Data/bilgi.mdb"

SelectCommand="SELECT [id], [BASLIK], [HIT] FROM [anket]">

</asp:AccessDataSource>

</form>

</body>

</html>

 

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN