[求助]gridview后台绑定数据分页

lihaoran8577 2010-11-30 04:42:21
show.aspx

<div style="width:100%;margin:10px auto;">
<div style="background-image:url(image/date_bg.gif);width:100%;height:41px;padding-top:8px;border:1px solid #eee;">
<asp:Button ID="ButtYesterDay" runat="server" Text="昨天" width="77px"
CssClass="but" onclick="ButtYesterDay_Click"/>
<asp:Button ID="ButtNearSenvenDay" runat="server" Text="最近7天" width="77px"
CssClass="but" onclick="ButtNearSenvenDay_Click"/>
<asp:Button ID="ButtNearThirtyDay" runat="server" Text="最近30天" width="77px"
CssClass="but" onclick="ButtNearThirtyDay_Click"/>
<asp:Button ID="ButtLastMonth" runat="server" Text="上一个月" width="77px"
CssClass="but" onclick="ButtLastMonth_Click"/>
从:<asp:TextBox ID="TextBStartTime" runat="server" CssClass="but" Width="100px" onfocus="setday(this);"></asp:TextBox>
至:<asp:TextBox ID="TextBEndTime" runat="server" CssClass="but" Width="100px" onfocus="setday(this);"></asp:TextBox>
请输入商品名称或ID<asp:TextBox ID="TextBSearch" runat="server" CssClass="but" Width="100px"></asp:TextBox>
<asp:Button ID="ButtQuery" runat="server" Text="查询" width="77px" CssClass="but"
onclick="ButtQuery_Click" />
<asp:GridView ID="GridViewBySearch" runat="server" Width="100%"
AutoGenerateColumns="False" CellPadding="0" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="缩略图">
<ItemTemplate>
<asp:Image ID="ImageProductUrl" runat="server" Width="80px" Height="80px" ImageUrl='<%# Eval("PicUrl")%>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="产品地址">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("CurrentPage")%>' Target="_blank"><%# Eval("ItemUrl")%></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="预览">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<a href="javascript:window.location.href='TwoProduct.aspx?ID='+escape('<%# Eval("CurrentPage") %>')" title="查看商品模版" target="_blank"><asp:Label ID="LabCurrentPage" runat="server" Text='<%# Eval("CurrentPage").ToString().Length > 50 ? Eval("CurrentPage").ToString().Substring(0, 50) + "..." : Eval("CurrentPage")%>'></asp:Label></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="更新">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Button ID="ButtonUpdate" runat="server" CommandArgument='<%#Eval("CurrentPage") %>' Text="更新" Width="77px" ToolTip="将信息更新到商品描述中" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="价格">
<ItemTemplate>
<asp:Label ID="LabelMoney" runat="server" Text='<%# Eval("ProcMoney")%>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="点击次数">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="LabelCount" runat="server" Text='<%# Eval("coun")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" ForeColor="White" OnClick="ButtonAutoSearch" CommandName="Page" CommandArgument="First" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex>0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="Page" ForeColor="White" CommandArgument="Prev" OnClick="ButtonAutoSearch" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex>0 %>">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Page" ForeColor="White" CommandArgument="Next" OnClick="ButtonAutoSearch" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex<((GridView)Container.Parent.Parent).PageCount-1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Page" ForeColor="White" CommandArgument="Last" OnClick="ButtonAutoSearch" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex<((GridView)Container.Parent.Parent).PageCount-1 %>">尾页</asp:LinkButton>
 <span style="font-family: Georgia;">第<asp:Label ID="Label2" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageIndex+1 %>'></asp:Label>页/共
<asp:Label ID="Label3" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageCount %>'></asp:Label>页 每页
<asp:Label ID="Label4" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageSize%>'></asp:Label>条记录</span>
</PagerTemplate>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</div>

...全文
328 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihaoran8577 2010-12-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yanimaziba 的回复:]
你的方法都已经写好了,简单的查数据分页而已。我不明白LZ到底要做什么?是不是想把SearchID()方法跟SearcheName()这两方法里面的参数中的前两个改成价格?用价格作为条件去查询数据 分页?
[/Quote]
当我调用ButtonAutoSearch分页时候,需要绑定数据~
因为我是根据搜索条件来执行查询的~所以我不知道到底是绑定SearchID()还是绑定SearcheName()~
jeven_xiao 2010-12-01
  • 打赏
  • 举报
回复
你的方法都已经写好了,简单的查数据分页而已。我不明白LZ到底要做什么?是不是想把SearchID()方法跟SearcheName()这两方法里面的参数中的前两个改成价格?用价格作为条件去查询数据 分页?
lihaoran8577 2010-12-01
  • 打赏
  • 举报
回复
lihaoran8577 2010-11-30
  • 打赏
  • 举报
回复
UPUPUPUPUPUPUPUP~
lihaoran8577 2010-11-30
  • 打赏
  • 举报
回复
show.aspx.cs

protected void ButtQuery_Click(object sender, EventArgs e)//搜索
{
strtime = TextBStartTime.Text;
endtime = TextBEndTime.Text;
serth = TextBSearch.Text;
GridViewByYestoday.Visible = false;
GridViewByThreeDay.Visible = false;
GridViewByServenDay.Visible = false;
GridViewBySearch.Visible = true;
GridViewByLastMonth.Visible = false;
if (TextBStartTime.Text != "" && TextBEndTime.Text != "")
{
string stOK = IsDate(TextBStartTime.Text);
string strNo = IsDate(TextBEndTime.Text);
if (stOK == "OK" && strNo == "OK")
{
if (DateTime.Parse(TextBEndTime.Text) > DateTime.Parse(TextBStartTime.Text))
{
if (TextBSearch.Text == "")
{
bindByYesToday(TextBSearch.Text,TextBEndTime.Text,GridViewBySearch);
}
else
{
string strSearch = TextBSearch.Text;
if (CheckCharIsNumber(strSearch))
{
SearchID(TextBStartTime.Text, TextBEndTime.Text, strSearch);
}
else
{
SearchName(TextBStartTime.Text, TextBEndTime.Text, strSearch);
}
}
}
else
{
ClassData.WebMessageBox(Page, "您的结束日期比起始日期小,请更正后再次输入!", "");
}
}
else
{
ClassData.WebMessageBox(Page, "请正确输入日期格式!", "");
}
}
else
{
ClassData.WebMessageBox(Page, "请输入您要选择的日期区间", "");
}
}
public static string IsDate(string StrSource)
{
DateTime dt;
if (DateTime.TryParse(StrSource, out dt))
{
return "OK";
}
else
{
return "NO";
}
}
private void SearchID(string strTime, string endTime, string strID)
{
string sqlStr = "select CurrentPage,PicUrl,ItemUrl,ProcMoney,count(*) as coun from pro where ItemUrl != '' and CreateDate between '" + strTime + " 00:00:00' and '" + endTime + " 23:59:59' and CurrentPage like '%" + strID + "%' group by CurrentPage,ItemUrl,PicUrl,ProcMoney,ItemUrl order by coun desc";
SqlConnection myConn = new SqlConnection("server=sa;database=show;uid=sa;pwd=sa;");
SqlDataAdapter myAdapter = new SqlDataAdapter(sqlStr, myConn);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "authors");
GridViewBySearch.DataSource = ds.Tables["authors"];
GridViewBySearch.AllowPaging = true;//设置他可以分页,前台必须设置分页模板不可见,否则他要使坏
GridViewBySearch.PageSize = 10;//分页大小为10
GridViewBySearch.DataBind();
}
private void SearchName(string strTime, string endTime, string strName)//根据搜索条件找出符合条件的数据绑定到gridview
{
string sqlStr = "select CurrentPage,PicUrl,ItemUrl,ProcMoney,count(*) as coun from pro where ItemUrl like '%" + strName + "%' ItemUrl != '' and CreateDate between '" + strTime + " 00:00:00' and '" + endTime + " 23:59:59' group by CurrentPage,PicUrl,ProcMoney,ItemUrl order by coun desc";
SqlConnection myConn = new SqlConnection("server=sa;database=show;uid=sa;pwd=sa;");
SqlDataAdapter myAdapter = new SqlDataAdapter(sqlStr, myConn);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "authors");
GridViewBySearch.DataSource = ds.Tables["authors"];
GridViewBySearch.AllowPaging = true;//设置他可以分页,前台必须设置分页模板不可见,否则他要使坏
GridViewBySearch.PageSize = 10;//分页大小为10
GridViewBySearch.DataBind();
}
public bool CheckCharIsNumber(string strtempstr)
{
bool returntempbool = true;
for (int i = 0; i < strtempstr.Length; i++)
{
if (!Char.IsNumber(strtempstr, i))
{
returntempbool = false;
}
}
return returntempbool;
}
protected void ButtonAutoSearch(object sender, EventArgs e)//分页
{
switch (((LinkButton)sender).CommandArgument.ToString())
{
case "First":
GridViewByLastMonth.PageIndex = 0;
break;
case "Last":
GridViewByLastMonth.PageIndex = GridViewByLastMonth.PageCount - 1;
break;
case "Prev":
GridViewByLastMonth.PageIndex = GridViewByLastMonth.PageIndex - 1;
break;
case "Next":
GridViewByLastMonth.PageIndex = GridViewByLastMonth.PageIndex + 1;
break;
}
//需要绑定数据函数,可以该调用那个?绑定SearchName()还是SearchID();应该价格判断,
}
课程首先介绍了Flutter的主要知识,通过4个案例消化吸收知识点。并通过手把手一步步带您完成一个【我的备忘录】APP项目,使得您真正认识Flutter在实际项目中的优势。  通过本课程学习您可以学习到Flutter技术如下知识:第1章 Flutter概述知识点:移动应用开发现状、移动应用开发类型、Hybrid与移动跨平台开发策略、Flutter是什么?、Flutter特点、Flutter体系结构。第2章 Flutter开发环境搭建知识点:基于Windows的Android开发环境、基于macOS的iOS开发环境、IDE开发工具设置。第3章 Flutter基础知识点:完成一个Flutter程序、一切都是组件(Widget)、组件分类、使用图片和图标资源、使用文本组件、增加调试组件工具。第4章 布局组件知识点:Flutter布局概述、容器布局(Container)、行(Row)、列(Column)布局、层叠布局、ListView、GridView。第5章 Material风格组件知识点:按钮、输入框、复选框、单选按钮、开关按钮、滑块。第6章 iOS Cupertino风格组件知识点:iOS Cupertino页面、Cupertino按钮、Cupertino开关按钮、Cupertino滑块、Cupertino分段控件。第7章 状态管理知识点:状态管理概述、局部状态管理、全局状态管理。第8章 导航知识点:导航概述、面包屑导航、标签导航、页面组件分散在不同文件中、全局状态管理与导航。第9章 工程依赖管理知识点:工程依赖管理概述、pub依赖管理工具。第10章 数据存储知识点:Flutter数据存储策略、键值对数据存储、文件数据存储、SQLite数据存储、示例:数据CRUD操作。第11章 网络通信知识点:搭建自己的Web服务器、使用http包、示例:城市信息列表。第12章 项目实战:我的备忘录APP知识点:备忘录APP项目说明、备忘录项目后台Web服务API说明、备忘录APP项目分析与设计、初始化工程、持久层实现、表示层实现。 

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧