不局限于GridView。
bind();//调用数据绑定即可
总之:善用CSS的word-break:break-all;word-wrap:break-word属性即可,GridView操作(4)风雷动演员表。在RowDataBound中添加上了一句e.Row.Cells[2].Style.Add("word-break", "break-all")就可以。+。
if (!IsPostBack)
GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
//下面这行是自动换行
GridView1.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
//正常换行
protected void Page_Load(object sender, EventArgs e)
如果要给所有的列增加此属性:想知道。
原因是连续英文段为一个整体导致的,演员表。显示的时候在一行里面显示,要加的RowState判断
gridview里有一列绑定的数据很长,GridView操作(4)风雷动演员表。避免出错,我不知道
GridView操作(4)风雷动演员表? + GridView1 听听GridView1。行背景色变
首先设置<asp:BoundField DataField="家庭住址" HeaderText="家庭住址" ItemStyle-Width="100" />
效果图:
11.GridView一般换行与强制换行:GridView1。
e.Row.Cells[0].Text = id.ToString();
int id = e.Row.RowIndex + 1;
if (e.Row.RowIndex != -1)
// ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:学习操作。\"" + e.Row.Cells[1].Text + "\"吗?')");
//if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
////当有编辑列时,行背景色变
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
////鼠标移出时,学习gridview1。行背景色变
//e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
////鼠标经过时,学习gridview。
if (e.Row.RowType == DataControlRowType.DataRow)
//如果是绑定数据行
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
return sNewStr;
sNewStr = sNewStr + "...";
string sNewStr = sString.Substring(0, nLeng);
return sString;
if (sString.Length <= nLeng)
public string SubStr(string sString, int nLeng)
sqlcon.Close();
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
gIntro = Convert.ToString(mydrv["家庭住址"]);
mydrv = myds.Tables["飞狐工作室"].DefaultView[i + (5 * GridView1.PageIndex)];
else
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
gIntro = Convert.ToString(mydrv["家庭住址"]);
mydrv = myds.Tables["飞狐工作室"].DefaultView[i];
if (GridView1.PageIndex == 0)
string gIntro;
DataRowView mydrv;
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
GridView1.DataBind();
GridView1.DataKeyNames = new string[] { "身份证号码" };
GridView1.DataSource = myds;
myda.Fill(myds, "飞狐工作室");
sqlcon.Open();
DataSet myds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
sqlcon = new SqlConnection(strCon);
string sqlstr = "select top 5 * from 飞狐工作室";
public void bind()
bind();
GridView1.EditIndex = -1;
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
bind();
GridView1.EditIndex = -1;
sqlcon.Close();
sqlcom.ExecuteNonQuery();
sqlcon.Open();
sqlcom=new SqlCommand(sqlstr,sqlcon);
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "' where 身份证号码='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',家庭住址='"
string sqlstr = "update 飞狐工作室 set 姓名='"
sqlcon = new SqlConnection(strCon);
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
bind();
sqlcon.Close();
sqlcom.ExecuteNonQuery();
sqlcon.Open();
sqlcom = new SqlCommand(sqlstr,sqlcon);
sqlcon = new SqlConnection(strCon);
string sqlstr = "delete from 飞狐工作室 where 身份证号码='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
bind();
GridView1.EditIndex = e.NewEditIndex;
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
bind();
ViewState["OrderDire"] = "ASC";
ViewState["SortOrder"] = "身份证号码";
if (!IsPostBack)
protected void Page_Load(object sender, EventArgs e)
string strCon = "Data Source=(local);Database=北风贸易;Uid=sa;Pwd=sa";
SqlCommand sqlcom;
SqlConnection sqlcon;
public partial class _Default : System.Web.UI.Page
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.Security;
using System.Web;
using System.Configuration;
using System.Data;
using System;
后台全部代码:
return sNewStr;
sNewStr = sNewStr + "...";
string sNewStr = sString.Substring(0, nLeng);
return sString;
if (sString.Length <= nLeng)
public string SubStr(string sString, int nLeng)
调用的方法:风雷动。
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
gIntro = Convert.ToString(mydrv["家庭住址"]);
mydrv = myds.Tables["飞狐工作室"].DefaultView[i + (5 * GridView1.PageIndex)];
else
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
gIntro = Convert.ToString(mydrv["家庭住址"]);//所要处理的字段
mydrv = myds.Tables["飞狐工作室"].DefaultView[i];//表名
if (GridView1.PageIndex == 0)
string gIntro;
DataRowView mydrv;
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
解决方法:数据绑定后过滤每一行即可
11.GridView实现用“...”代替超长字符串:。效果图:我不知道gridview。
+(责任编辑:admin) |