.net学习总结(5)之Gridview控件,智能搜索
来源:互联网 发布:筑龙投标软件 编辑:程序博客网 时间:2024/05/01 09:15
17. 报错:“将截断字符串或二进制数据。语句已终止。”
原因:(1)可能数据库的类型与程序的数据类型不一至。(2)可能数据表中数据长度过短。
18. girdview 分页PageIndexChanging事件问题--激发了未处理的事件"PageIndexChanging"
修改方法:1) 添加OnPageIndexChanging事件,OnPageIndexChangin="GridView1_PageIndexChanging
2)要cs页面中添加
- protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
- {
- GridView1.PageIndex = e.NewPageIndex;
- DataBind();
- }
19. 如何在 girdview分页中得到总的记录数
方法一、使用datatable取得数据源,然后用ds.Rows.Count便可以取得总的记录数。
- {
- DataTable ds = sqlcontrol.Table_jl(sql1);
- //或者使用DataSet,
- //DateSet ds=new DataSet();
- //int count=ds.Table[0].Rows.Count;
- int cout = ds.Rows.Count;
- Label1.Text = "共有留言:" + cout.ToString() + "条";
- han.DataSource = ds;
- han.DataBind();
- }
方法二、网上的,不过没用过,先写上。在sqldatasource的selected事件中,取e.affectrow 值(select所影响的行数)。
20.智能搜索;
- private string jshan(string han, string ziduan)//第一个参数是搜索的关键字,第二个字段是数据表中的字段。
- {
- int lngLenKey = han.Length;//取得关键字的长度
- string strNew1 = "";
- string stRSTubKey;
- const int lngSubKey = 3;
- if (lngLenKey == 0)
- {
- strNew1 = "";
- }
- else
- {
- int i = 1;
- while (i <= (lngLenKey - (lngSubKey - 1)))
- {//把关键字分解成每两个字组成的词,分别按分解成的词搜索与之相匹配的。
- stRSTubKey = han.ToString().Substring(i, 2);
- strNew1 = strNew1 + " or " + ziduan + " like '%" + stRSTubKey + "%'";
- i = i + 1;
- }
- }
- return strNew1;
-
- }
- string sql1 = "Select * from [News] where ntitle like '%" + scontent + "%'" + jshan(scontent, "ntitle");
- // 从News表中ntitle字段中搜素与关键字匹配的。
附加贴一个组合查询的方法:
- //查询语句
- public void sql()//
- {
- string lbjs = "全部数据";
- sqlCedar = "select * from HCDetaile where 1=1 ";
- if (SZH.Checked == true)//如果是组合查询
- {
- lbjs = "组合查询结果";
- string Stime = cr.formatDate(Convert.ToDateTime(SBirthDayTime.Text)).ToString();
- string Etime = cr.formatDate(Convert.ToDateTime(EBirthDayTime.Text)).ToString();
- sqlCedar += " and (BrithTime between '" + Stime + "' and '" + Etime + "') ";
- if (Rsex.Text != "0")
- {
- sqlCedar += " and UserSex='" + Rsex.Text + "'";
- lbjs += "--性别:" + Rsex.Text;
- }
- if (Marry.Text != "0")
- {
- sqlCedar += " and Marry='" + Marry.Text + "'";
- lbjs += "--婚否:" + Marry.Text;
- }
- if (Distinction.Text != "0")
- sqlCedar += " and Distinction='" + Distinction.Text + "'";
- if (Degree.Text != "0")
- sqlCedar += " and Degree='" + Degree.Text + "'";
- if (userName2.Text != "")
- {
- sqlCedar += " and ( UserName like '%" + userName2.Text + "%') ";
- lbjs += "--关键字:" + userName2.Text;
- }
- }
- else
- {
- if (userName.Text.Trim() != "")
- {
- sqlCedar += " and UserName like '%" + userName.Text + "%'";
- lbjs = "搜索的关键字:" + userName.Text;
- }
- }
- lbjg.Text = lbjs;
- lbjg.Visible = true;
- }
- //执行查询并绑定数据
- public void databin()
- {
- sql();
- DataSet ds = dc.Query(sqlCedar, 0, 0);
- DataTable dt = ds.Tables[0];
- if (dt.Rows.Count != 0)
- {
- //增加新的一列
- DataColumn dl = dt.Columns.Add("number", System.Type.GetType("System.String"));
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- dt.Rows[i]["number"] = (i + 1).ToString();
- }
- //绑定数据,分页显示
- PagedDataSource pds = new PagedDataSource();
- Pager1.RecordCount = dt.Rows.Count;
- pds.DataSource = ds.Tables[0].DefaultView;
- pds.AllowPaging = true;
- pds.CurrentPageIndex = Pager1.CurrentPageIndex - 1;
- pds.PageSize = Pager1.PageSize;
- Custom.DataSource = pds;
- Custom.DataBind();
- chkAll.Visible = true;
- LinkButton11.Visible = true;
- Linkmove.Visible = true;
- }
- else
- {
- Custom.DataBind();
- chkAll.Visible = false;
- LinkButton11.Visible = false;
- Linkmove.Visible = false;
- }
- }
- .net学习总结(5)之Gridview控件,智能搜索
- asp.net 学习之路之gridView控件(续)
- asp.net 学习之路之gridView控件
- .net学习总结(3)之数据绑定,DropDownList控件
- 《Programming ASP.NET》学习笔记(GridView控件)
- asp.net高级应用之GridView控件(2)
- ASP.NET学习之GridView
- asp.net 学习之路之gridView控件之修改数据
- asp.net控件之gridview编程
- ASP.NET服务器控件使用之GridView
- asp.net高级应用之GridView控件
- 黑马程序员之 ASP.NET学习笔记:GridView控件的常用属性及方法
- ASP.NET之GridView常用方法总结
- Android基础学习之GridView控件
- asp.net gridview控件
- Asp.Net 控件 GridView
- Asp.Net 控件 GridView
- Asp.Net总结(三)GridView
- 三十四个超级经典小故事
- GDB使用手册
- 基于Eclipse开发OSGI的简单实例
- sql中把字符型转成整型
- CPU调度算法演示
- .net学习总结(5)之Gridview控件,智能搜索
- uml的组成
- 走进PIMShell(4)--网页的架构htm/xml/js
- Hibernate入门
- Asterisk拨号方案语法基础
- 出租车“起步价”
- How to Create Dynamic Settings Pages
- [笔记]经验分享:流量大的网站可以采用静态gzip压缩某些页面及文件
- hibernate更新数据