GridView实现用...代替超长字符串
后台全部代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
//QQ:272912705 光之翼 www.hi.baidu.com/jcomet
SqlConnection sqlcon;
SqlCommand sqlcom;
string strCon = "Data Source=(local);Database=北风贸易;Uid=sa;Pwd=sa";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["SortOrder"] = "身份证号码";
ViewState["OrderDire"] = "ASC";
bind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from 飞狐工作室 where 身份证号码='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlcon = new SqlConnection(strCon);
sqlcom = new SqlCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "update 飞狐工作室 set 姓名='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',家庭住址='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "' where 身份证号码='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlcom=new SqlCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}
public void bind()
{
string sqlstr = "select top 5 * from 飞狐工作室";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "飞狐工作室");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] { "身份证号码" };
GridView1.DataBind();
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
DataRowView mydrv;
string gIntro;
if (GridView1.PageIndex == 0)
{
mydrv = myds.Tables["飞狐工作室"].DefaultView[i];
gIntro = Convert.ToString(mydrv["家庭住址"]);
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
}
else
{
mydrv = myds.Tables["飞狐工作室"].DefaultView[i + (5 * GridView1.PageIndex)];
gIntro = Convert.ToString(mydrv["家庭住址"]);
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
}
}
sqlcon.Close();
}
public string SubStr(string sString, int nLeng)
{
if (sString.Length <= nLeng)
{
return sString;
}
string sNewStr = sString.Substring(0, nLeng);
sNewStr = sNewStr + "...";
return sNewStr;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
鼠标经过时,行背景色变
//e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
鼠标移出时,行背景色变
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
当有编辑列时,避免出错,要加的RowState判断
//if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
//{
// ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
//}
}
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
}
转载于:https://www.cnblogs.com/jcomet/archive/2008/07/14/1242494.html
GridView实现用...代替超长字符串相关推荐
- js 字符串换行_JS代码编程中经常用到的超长字符串换行方法,你最喜欢哪一种?
编写js代码的时候,经常会用到超长字符串的拼接. 例如,把系统时间中的年.月.日.时.分.秒共6个数字动态拼接到一个tr行,不换行的话,将是一个超长的字符串,阅读.维护都不方便.这时就需要将这个字符串 ...
- oracle 字符超长,oracle存储超长字符串
oracle 字符.数值.日期处理_计算机软件及应用_IT/计算机_专业资料.字符及处理方法 1.固定长度字符串: char(n) 空格补足,效率高,最大 2000. 2.变长: varchar(n) ...
- oracle 拼接字符串超长,字符串连接超长的解决(一)
不过上面两种方法都会面临一个问题,就是如果聚集连接的字符串长度如果超过了VARCHAR2类型所允许的最大长度,就会导致字符串超长的错误. 自定义聚集函数这里就不重复了,可以参考上面的链接: SQL&g ...
- 如何设置省略号对其序号 html,html 用css实现table中超长字符串省略号表示 - 天天好心情 - 博客园...
最近学习样式,想用样式来控制GridView中超长字符的省略显示,可是网上从后台的方式是在让我诟病,当然,个人喜好问题:P 由于GridView最终是Table形式输出,于是从table实现该样式找 ...
- netty3超长字符串
本文链接:https://blog.csdn.net/MCpang/article/details/38613857 https://github.com/jacke121/androidTower/ ...
- Python 技巧篇-字符串灵活处理:字符串过滤、字符串拼接,字符串切片,特殊、超长字符串的处理实例演示
字符串简单处理的话用字符串切片很容易实现, 形如:a="Hello Python!",a[-7:]="Python!", 规则:大于等于冒号前的小于冒号后的,两 ...
- ajax如何传超长字符串_解决ajax超长字符串、中文乱码问题
在最近的项目测试中发现通过ajax发送超长参数时遇到这个脚本错误: 系统找不到指定资源 the system cannot locate the resource specified 意思是参数太长, ...
- python字符串换行的三种方式_Python:怎样拼装超长字符串和包含回车换行字符串...
Python 中字符串可以使用单引号('--')或双引号("--")表示.反斜杠 \ 是转义字符.如果你不希望 \ 转义字符成特殊字符,可以在引号前添加 r 即可.如下所示: &q ...
- Java中关于超长字符串压缩,解压缩问题
问题:数据库中varchar类型的长度设置为5000,通过一个富文本编辑器编辑了通知内容,接收到了内容字段长度为8000多,unruly数据库时候,数据库报错(字段太长,显示下标越界异常) 解决办法: ...
最新文章
- 【[HAOI2011]Problem c】
- 11月29日云栖精选夜读:阿里传奇工程师多隆的程序世界
- TOA定位算法的FPGA实现
- MFC和GTK的区别
- 自我接纳_接纳预测因子
- hystrix 页面_《SpringCloud微服务之Hystrix组件》
- python链表值讲解_python数据结构之链表的实例讲解
- discuz论坛添加水印
- CCF201604-3 路径解析(解法三)(90分)(废除!!!)
- BZOJ1767/Gym207383I CEOI2009 Harbingers 斜率优化、可持久化单调栈、二分
- 《BDD100K: A Diverse Driving Dataset for Heterogeneous Multitask Learning》论文阅读笔记
- 华为云文件夹服务器,华为云文件夹服务器
- 极限-确定常数使得阶数尽可能为高的无穷小
- 五万字 | Hive知识体系保姆级教程
- 微信网页audio标签无法正常播放音频
- linux卸载nginx(更新)
- 个股期权交易系统为什么和私密机构紧密相连?
- 刷个openwrt,并加入改写的802.1X认证客户端(iNode认证)
- 光伏电站清扫机器人_光伏清扫机器人(GF01B)
- 输出杨辉三角的前N行