虚心求教 10
想在ASP.NET中实现将搜索结果在GRIDVIEW控键中实现分页显示,建立了搜索按钮,用手写输入的方法输入了以下代码publicpartialclass_Default...
想在ASP.NET中实现将搜索结果在GRIDVIEW控键中实现分页显示,建立了搜索按钮,用手写输入的方法输入了以下代码
public partial class _Default : System.Web.UI.Page
{
public DataView m_dataview;
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = m_dataview;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.PagerSettings.Mode = PagerButtons.Numeric;
string a = "Data Source=localhost;Initial Catalog=网上购书系统;Integrated Security=True";
SqlConnection b = new SqlConnection(a); //建立连接
b.Open();
string bt = Convert.ToString(TextBox1.Text);
SqlCommand c = new SqlCommand("select * from 图书信息 where 图书类别='" + bt + "'", b); // 建立SQL语句
c.CommandType = System.Data.CommandType.Text; //设计查询的文本格式
c.Connection = b; //登录方式
SqlDataAdapter m = new SqlDataAdapter();
m.SelectCommand = c;
DataSet s = new DataSet();
m.Fill(s);
m_dataview = s.Tables[0].DefaultView;
GridView1.DataSource = m_dataview;
GridView1.DataBind();
b.Close();
}
}
输入后可以查询结果但无法分页显示,点页号就刷新成空白页,在ASPX中
<asp:GridView ID="GridView1" runat="server" Height="339px" Width="390px" AllowPaging="True" ForeColor="#00C000" PageSize="3"
OnPageIndexChanging="GridView1_PageIndexChanging" PagerStyle-HorizontalAlign="Right" AutoGenerateColumns="True">
<PagerStyle HorizontalAlign="Right" />
</asp:GridView>
第一次学做,求指点怎么实现分页,还要加什么 展开
public partial class _Default : System.Web.UI.Page
{
public DataView m_dataview;
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = m_dataview;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.PagerSettings.Mode = PagerButtons.Numeric;
string a = "Data Source=localhost;Initial Catalog=网上购书系统;Integrated Security=True";
SqlConnection b = new SqlConnection(a); //建立连接
b.Open();
string bt = Convert.ToString(TextBox1.Text);
SqlCommand c = new SqlCommand("select * from 图书信息 where 图书类别='" + bt + "'", b); // 建立SQL语句
c.CommandType = System.Data.CommandType.Text; //设计查询的文本格式
c.Connection = b; //登录方式
SqlDataAdapter m = new SqlDataAdapter();
m.SelectCommand = c;
DataSet s = new DataSet();
m.Fill(s);
m_dataview = s.Tables[0].DefaultView;
GridView1.DataSource = m_dataview;
GridView1.DataBind();
b.Close();
}
}
输入后可以查询结果但无法分页显示,点页号就刷新成空白页,在ASPX中
<asp:GridView ID="GridView1" runat="server" Height="339px" Width="390px" AllowPaging="True" ForeColor="#00C000" PageSize="3"
OnPageIndexChanging="GridView1_PageIndexChanging" PagerStyle-HorizontalAlign="Right" AutoGenerateColumns="True">
<PagerStyle HorizontalAlign="Right" />
</asp:GridView>
第一次学做,求指点怎么实现分页,还要加什么 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询