在一网页上加控件如下:
textbox1 button1 gridview1 sqldatasource1设置sqldatasource1数据源为SQL2000中的一个表查询
设置gridview1为分页,其数据源为sqldatasource1
设置按钮事件:改变gridview1的查询,以textbox1筛选,即:select * from item where t1=textbox1.TEXT运行后结果正常,能分页,当有很多页时,但单击页码2或其它页时,显示为空请问,如何能显示其它页出来,TKS!
textbox1 button1 gridview1 sqldatasource1设置sqldatasource1数据源为SQL2000中的一个表查询
设置gridview1为分页,其数据源为sqldatasource1
设置按钮事件:改变gridview1的查询,以textbox1筛选,即:select * from item where t1=textbox1.TEXT运行后结果正常,能分页,当有很多页时,但单击页码2或其它页时,显示为空请问,如何能显示其它页出来,TKS!
Partial Class item
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim phase As String
Select Case DropDownList2.SelectedValue
Case "采购的" : phase = "P"
Case "制造的" : phase = "M"
Case "转移的" : phase = "T"
End Select Dim SqlStr As String
SqlStr = "select item,description,uf_CName,UF_Specifications1" + _
",UF_Specifications2,uf_EngUM,lead_time,product_code,p_m_t_code" + _
",uf_BOMStatus,UF_CommonMaterial,Uf_FileCode,UF_ItemActive,UF_VendorItem,Uf_Catalog from item" + _
" where p_m_t_Code='" + phase + "'" If TextBox1.Text <> "" Then
Select Case DropDownList1.SelectedValue
Case "部品号" : SqlStr = SqlStr + " and item like N'%" + TextBox1.Text + "%'"
Case "中文名称" : SqlStr = SqlStr + " and uf_CName like N'%" + TextBox1.Text + "%'"
Case "英文名称" : SqlStr = SqlStr + " and description like N'%" + TextBox1.Text + "%'"
Case "规格" : SqlStr = SqlStr + " and (UF_Specifications1 like N'%" + TextBox1.Text + "%'" + _
" or UF_Specifications2 like N'%" + TextBox1.Text + "%')"
Case "类别" : SqlStr = SqlStr + " and Uf_Catalog like N'%" + TextBox1.Text + "%'"
Case "客户品号" : SqlStr = SqlStr + " and UF_VendorItem like N'%" + TextBox1.Text + "%'"
End Select
End If
SqlDataSource1.SelectCommand = SqlStr End SubEnd Class
{
DataSet ds = new DataSet();
string sql = "";
ds = sda.getDataSet(sql);
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
this.GridView1.Visible = true;
LblCurrentIndex.Text = "第 " + (GridView1.PageIndex + 1).ToString() + " 页";
LblPageCount.Text = "共 " + GridView1.PageCount.ToString() + " 页";
LblRecordCount.Text = "总共 " + ds.Tables[0].Rows.Count.ToString() + " 条";
btnFirst.Visible = true;
btnPrev.Visible = true;
btnNext.Visible = true;
btnLast.Visible = true; LblCurrentIndex.Visible = true;
LblPageCount.Visible = true;
LblRecordCount.Visible = true;
ddlCurrentPage.Visible = true;
jumto.Visible = true;
ye.Visible = true; if(GridView1.PageIndex==0){
btnFirst.Visible = false;
btnPrev.Visible = false;
} if(GridView1.PageIndex==GridView1.PageCount-1){
btnLast.Visible = false;
btnNext.Visible = false;
}
if (GridView1.PageCount == 1)
{
btnFirst.Visible = false;
btnPrev.Visible = false;
btnNext.Visible = false;
btnLast.Visible = false;
} // 计算生成分页页码,分别为:"首 页" "上一页" "下一页" "尾 页"
btnFirst.CommandName = "1";
btnPrev.CommandName = (GridView1.PageIndex == 0 ? "1" : GridView1.PageIndex.ToString());
protected void PagerButton_Click(object sender, EventArgs e)
{ //首先要得到數據集 GridView1.PageIndex = Convert.ToInt32(((LinkButton)sender).CommandName) - 1;
getdata();
} protected void btn1_Click(object sender, EventArgs e)
{
GridView1.PageIndex = 0;
getdata();
} btnNext.CommandName = (GridView1.PageCount == 1 ? GridView1.PageCount.ToString() : (GridView1.PageIndex + 2).ToString());
btnLast.CommandName = GridView1.PageCount.ToString();
// this.ddlCurrentPage.Items.Clear();
for (int i = 1; i <= this.GridView1.PageCount; i++)
{
this.ddlCurrentPage.Items.Add(i.ToString());
}
this.ddlCurrentPage.SelectedIndex = this.GridView1.PageIndex;
}
else
{
Response.Write("<script language='javascript'>alert('沒有符合的結果')</script>");
this.GridView1.Visible = false; }
}
else
{
Response.Write("<script language='javascript'>alert('沒有符合的結果')</script>");
this.GridView1.Visible = false; } }
<div style=" height:16px; padding-top:5px; margin-right:30px; float:right; width: 625px;">
<asp:LinkButton ID="btnFirst" CommandArgument="first" OnClick="PagerButton_Click"
runat="server">首 页</asp:LinkButton>
<asp:LinkButton ID="btnPrev" CommandArgument="prev" OnClick="PagerButton_Click" runat="server">上一页</asp:LinkButton>
<asp:LinkButton ID="btnNext" CommandArgument="next" OnClick="PagerButton_Click" runat="server">下一页</asp:LinkButton>
<asp:LinkButton ID="btnLast" CommandArgument="last" OnClick="PagerButton_Click" runat="server">尾 页</asp:LinkButton>
<asp:Label ID="LblCurrentIndex" runat="server"></asp:Label>
<asp:Label ID="LblPageCount" runat="server"></asp:Label>
<asp:Label ID="LblRecordCount" runat="server"></asp:Label>
<asp:Label ID="jumto" runat="server" Text=" 跳转到第"></asp:Label>
<asp:DropDownList ID="ddlCurrentPage" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:Label ID="ye" runat="server" Text=" 页"></asp:Label>
<asp:HiddenField ID="CurrentPage" runat="server" Value="0"/>
</div>