日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

gridView总结

發布時間:2025/4/14 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 gridView总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

GridView 72般絕技

-----------GridView綁定行號------------
<%#DataBinder.Eval(Container,"RowIndex") %>

1.GridView無代碼分頁排序
??? 1.1.AllowSorting設為True,aspx代碼中是AllowSorting="True";
??? 1.2..默認1頁10條,如果要修改每頁條數,修改PageSize即可,在aspx代碼中是PageSize="12"。
??? 1.3.默認的是單向排序的,右擊GridView彈出“屬性”,選擇AllowSorting為True即可。

2.GridView選中,編輯,取消,刪除
??????? 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 id=''" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "''";????????????????????????????

??????? bind();
??? }

//更新
??? protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
??? ...{
??????? sqlcon = new SqlConnection(strCon);
??????? string sqlstr = "update 表 set 字段1=''"
??????????? + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "'',字段2=''"
??????????? + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "'',字段3=''"
??????????? + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "'' where id=''"
??????????? + GridView1.DataKeys[e.RowIndex].Value.ToString() + "''";
????
??????? GridView1.EditIndex = -1;
??????? bind();
??? }
//取消
??? protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
??? ...{
??????? GridView1.EditIndex = -1;
??????? bind();
??? }

//綁定
??? public void bind()
??? ...{
????
??????? GridView1.DataSource = myds;
??????? GridView1.DataKeyNames = new string[] ...{ "id" };//主鍵
??????? GridView1.DataBind();

??? }

3.GridView正反雙向排序

??????? public partial class Default3 : System.Web.UI.Page
??????? ...{
??????????? protected void Page_Load(object sender, EventArgs e)
??????????? ...{
??????????????? if (!IsPostBack)
??????????????? ...{
??????????????????? ViewState["SortOrder"] = "身份證號碼";
??????????????????? ViewState["OrderDire"] = "ASC";
??????????????????? bind();
??????????????? }
??????????? }
??????????? protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
??????????? ...{
??????????????? string sPage = e.SortExpression;
??????????????? if (ViewState["SortOrder"].ToString() == sPage)
??????????????? ...{
??????????????????? if (ViewState["OrderDire"].ToString() == "Desc")
??????????????????????? ViewState["OrderDire"] = "ASC";
??????????????????? else
??????????????????????? ViewState["OrderDire"] = "Desc";
??????????????? }
??????????????? else
??????????????? ...{
??????????????????? ViewState["SortOrder"] = e.SortExpression;
??????????????? }
??????????????? bind();
??????????? }

??????????? public void bind()
??????????? ...{
??????????????? myda.Fill(myds, "飛狐工作室");
??????????????? DataView view = myds.Tables["飛狐工作室"].DefaultView;
??????????????? string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];
??????????????? view.Sort = sort;
??????????????? GridView1.DataSource = view;
??????????????? GridView1.DataBind();
??????????? }
??????? }
4.GridView和下拉菜單DropDownList結合
??? protected void Page_Load(object sender, EventArgs e)
??? ...{
??????? DropDownList ddl;
??????? if (!IsPostBack)
??????? ...{
??????????? 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.DataBind();
??????????? for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
??????????? ...{
??????????????? DataRowView mydrv = myds.Tables["飛狐工作室"].DefaultView[i];
??????????????? if (Convert.ToString(mydrv["員工性別"]).Trim() == "True")
??????????????? ...{
??????????????????? ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
??????????????????? ddl.SelectedIndex = 0;
??????????????? }
??????????????? if (Convert.ToString(mydrv["員工性別"]).Trim() == "False")
??????????????? ...{
??????????????????? ddl = (DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
??????????????????? ddl.SelectedIndex = 1;
??????????????? }
??????????? }
??????????? sqlcon.Close();
??????? }
??? }
??? public SqlDataReader ddlbind()
??? ...{
??????? string sqlstr = "select distinct 員工性別 from 飛狐工作室";
??????? sqlcon = new SqlConnection(strCon);
??????? SqlCommand sqlcom = new SqlCommand(sqlstr, sqlcon);
??????? sqlcon.Open();
??????? return sqlcom.ExecuteReader();
??? }
5.GridView和CheckBox結合

//checkBox在外部
?protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
??? ...{
??????? for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
??????? ...{
??????????? CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
??????????? if (CheckBox2.Checked == true)
??????????? ...{
??????????????? cbox.Checked = true;
??????????? }
??????????? else
??????????? ...{
??????????????? cbox.Checked = false;
??????????? }
??????? }
??? }
??? //遍例刪除
????? protected void Button2_Click(object sender, EventArgs e)
??? ...{
?
??????? for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
??????? ...{
??????????? CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
??????????? if (cbox.Checked == true)
??????????? ...{
?????????????? string id =? GridView1.DataKeys[i].Value;
????????
??????????? }
??????? }???????
6.GridView實現刪除時彈出確認對話框
?protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
????? ...{
??????? //如果是綁定數據行??? 當有編輯列時,避免出錯,要加的RowState判斷
??????? if (e.Row.RowType == DataControlRowType.DataRow)
??????? ...{
??????????? 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 + ""嗎?'')");
??????????? }
??????? }
??? }
7.GridView實現自動編號
??? 在后臺的GridView1_RowDataBound()方法添加代碼,最后代碼如下所示:
??? protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
??? ...{
??????? //如果是綁定數據行 //清清月兒http://blog.csdn.net/21aspnet
??????? if (e.Row.RowType == DataControlRowType.DataRow)
??????? ...{
??????????? /**/鼠標經過時,行背景色變
??????????? e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=''#E6F5FA''");
??????????? /**/鼠標移出時,行背景色變
??????????? e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''#FFFFFF''");
??????? }
??????? if (e.Row.RowIndex != -1)
??????? ...{
??????????? int id = e.Row.RowIndex + 1;
??????????? e.Row.Cells[0].Text = id.ToString();
??????? }
??? }
注意這時最好把前臺的第一列的表頭該為“編號”,因為以前的第一列被“吃掉”了。

8.GridView實現自定義時間貨幣等字符串格式
??? 解決方法:
??? 在asp.net 2.0中,如果要在綁定列中顯示比如日期格式等,如果用下面的方法是顯示不了的
??? <asp :BoundField DataField="CreationDate"
??? DataFormatString="{0:M-dd-yyyy}"
??? HeaderText="CreationDate" />

??? 主要是由于htmlencode屬性默認設置為true,已防止XSS攻擊,安全起見而用的,所以,可以有以下兩種方法解決
??? 1、
??????? <asp :GridView ID="GridView1" runat="server">
??????? <columns>
??????? <asp :BoundField DataField="CreationDate"
??????? DataFormatString="{0:M-dd-yyyy}"
??????? HtmlEncode="false"
??????? HeaderText="CreationDate" />
??????? </columns>
??????? </asp>

??????? 將htmlencode設置為false即可
??? 2.另外的解決方法為,使用模版列
??? <asp :GridView ID="GridView3" runat="server" >
??? <columns>
??? <asp :TemplateField HeaderText="CreationDate" >
??? <edititemtemplate>
??? <asp :Label ID="Label1" runat="server"
??? Text=''<%# Eval("CreationDate", "{0:M-dd-yyyy}") %>''>
??? </asp>
??? </edititemtemplate>
??? <itemtemplate>
??? <asp :Label ID="Label1" runat="server"
??? Text=’<%# Bind("CreationDate", "{0:M-dd-yyyy}") %>''>
??? </asp>
??? </itemtemplate>
??? </asp>
??? </columns>
??? </asp>
??? 附錄-常用格式化公式:
??? ...{0:C}? 貨幣;
??? ...{0:D4}由0填充的4個字符寬的字段中顯示整數;
??? ...{0:000.0}四舍五入小數點保留第幾位有效數字;
??? ...{0:N2}小數點保留2位有效數字;...{0:N2}%?? 小數點保留2位有效數字加百分號;
??? ...{0:D}長日期;...{0:d}短日期;...{0:yy-MM-dd}?? 例如07-3-25;;...{0:yyyy-MM-dd}? 例如2007-3-25
9 .GridView實現用“...”代替超長字符串
??? public void bind()
??? ...{
??????? 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[0].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);
??????????? }
??????? }
??? }

??? 調用的方法:
??? public string SubStr(string sString, int nLeng)
??? ...{
??????? if (sString.Length <= nLeng)
??????? ...{
??????????? return sString;
??????? }
??????? string sNewStr = sString.Substring(0, nLeng);
??????? sNewStr = sNewStr + "...";
??????? return sNewStr;
??? }
10.GridView一般換行與強制換行
??????? gridview里有一列綁定的數據很長,顯示的時候在一行里面顯示,頁面拉得很寬。
??? 原因是連續英文段為一個整體導致的,在RowDataBound中添加上了一句e.Row.Cells[2].Style.Add("word-break", "break-all")就可以。

??? 如果要給所有的列增加此屬性:
???? protected void Page_Load(object sender, EventArgs e)
??????? ...{
??????????? //正常換行
??????????? GridView1.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
??????????? //下面這行是自動換行
??????????? GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
??????????? if (!IsPostBack)
??????????? ...{
???????????????? bind();//調用數據綁定即可
??????????? }
??????? }
??? 總之:善用CSS的word-break:break-all;word-wrap:break-word屬性即可,這個屬性是通用的對于頑固的南換行問題都可以解決,不局限于GridView。

???
11.GridView顯示隱藏某一列
??? 雙擊CheckBox1,在CheckedChanged方法里寫上代碼,最后代碼如下:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
??? ...{
???????? GridView1.Columns[3].Visible=! GridView1.Columns[3].Visible;
???????? Response.Write("GridView1的第4列現在的顯示隱藏狀態是:"+GridView1.Columns[3].Visible.ToString());
??? }
???
12.GridView彈出新頁面/彈出新窗口
??? 方案二:精確控制彈出窗口大小位置
<asp:HyperLinkColumn DataNavigateUrlField="EmployeeID" DataNavigateUrlFormatString="javascript:varwin=window.open(''detail.aspx?ID={0}'',null,''width=300,height=200'');window.Close();"
?????? DataTextField="LastName" HeaderText="LastName"></asp:HyperLinkColumn>

使用的是結合javascript的window.open方法,關于window.open的參數網上有很多帖子,本站也有許多參考


13.GridView固定表頭(不用javascript只用CSS,2行代碼,很好用)
??? <head runat="server">
??? <title>GridView固定表頭 清清月兒http://blog.csdn.net/21aspnet </title>
??????? <style>
.Freezing
?? ...{
???
?? position:relative ;
?? table-layout:fixed;
?? top:expression(this.offsetParent.scrollTop);??
?? z-index: 10;
?? }

.Freezing th...{text-overflow:ellipsis;overflow:hidden;white-space: nowrap;padding:2px;}
</style>
</head>
...
?<div style="overflow-y: scroll; height: 200px;width:300px" id="dvBody">
?<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" CssClass="Freezing"/>
?</div>
?用法:CSS設如上的樣式,HeaderStyle加CssClass="Freezing,套住GridView的Div設置高度寬度 <div style="overflow-y: scroll; height: 200px;width:200px" >
?
14.GridView合并表頭多重表頭無錯完美版(以合并3列3行舉例)
??????? //這里就是解決方案
??? protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
??? ...{
??????? switch (e.Row.RowType)
??????? ...{
??????????? case DataControlRowType.Header:
??????????????? //第一行表頭
??????????????? TableCellCollection tcHeader = e.Row.Cells;
??????????????? tcHeader.Clear();
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[0].Attributes.Add("rowspan", "3"); //跨Row
??????????????? tcHeader[0].Attributes.Add("bgcolor", "white");
??????????????? tcHeader[0].Text = "";
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? //tcHeader[1].Attributes.Add("bgcolor", "Red");
??????????????? tcHeader[1].Attributes.Add("colspan", "6"); //跨Column
??????????????? tcHeader[1].Text = "全部信息</th></tr><tr>";

??????????????? //第二行表頭
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[2].Attributes.Add("bgcolor", "DarkSeaGreen");
??????????????? tcHeader[2].Text = "身份證號碼";
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[3].Attributes.Add("bgcolor", "LightSteelBlue");
??????????????? tcHeader[3].Attributes.Add("colspan", "2");
??????????????? tcHeader[3].Text = "基本信息";
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[4].Attributes.Add("bgcolor", "DarkSeaGreen");
??????????????? tcHeader[4].Text = "福利";
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[5].Attributes.Add("bgcolor", "LightSteelBlue");
??????????????? tcHeader[5].Attributes.Add("colspan", "2");
??????????????? tcHeader[5].Text = "聯系方式</th></tr><tr>";

??????????????? //第三行表頭
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[6].Attributes.Add("bgcolor", "Khaki");
??????????????? tcHeader[6].Text = "身份證號碼";
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[7].Attributes.Add("bgcolor", "Khaki");
??????????????? tcHeader[7].Text = "姓名";
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[8].Attributes.Add("bgcolor", "Khaki");
??????????????? tcHeader[8].Text = "出生日期";
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[9].Attributes.Add("bgcolor", "Khaki");
??????????????? tcHeader[9].Text = "薪水";
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[10].Attributes.Add("bgcolor", "Khaki");
??????????????? tcHeader[10].Text = "家庭住址";
??????????????? tcHeader.Add(new TableHeaderCell());
??????????????? tcHeader[11].Attributes.Add("bgcolor", "Khaki");
??????????????? tcHeader[11].Text = "郵政編碼";
??????????????? break;
??????? }
??? }
}

15.GridView突出顯示某一單元格(例如金額低于多少,分數不及格等)
??? protected void bind()
??? ...{
?????????????? for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
??????????? ...{
??????????????? DataRowView mydrv = myds.Tables["飛狐工作室"].DefaultView[i];
??????????????? string score = Convert.ToString(mydrv["起薪"]);
??????????????? if (Convert.ToDouble(score) < 34297.00)//大家這里根據具體情況設置可能ToInt32等
??????????????? ...{
??????????????????? GridView1.Rows[i].Cells[4].BackColor = System.Drawing.Color.Red;
??????????????? }
??????????? }
????? }
16.GridView加入自動求和求平均值小計(例如在購物車中,總計,平均)
??? private double sum = 0;//取指定列的數據和,你要根據具體情況對待可能你要處理的是int
??? protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
??????? ...{
??????????? if (e.Row.RowIndex >= 0)
??????????? ...{
??????????? //在第7列上運算
??????????????? sum += Convert.ToDouble(e.Row.Cells[6].Text);
??????????? }
??????????? else if (e.Row.RowType == DataControlRowType.Footer)
??????????? ...{
??????????????? e.Row.Cells[5].Text = "總薪水為:";
??????????????? e.Row.Cells[6].Text = sum.ToString();
??????????????? e.Row.Cells[3].Text = "平均薪水為:";
??????????????? e.Row.Cells[4].Text = ((int)(sum / GridView1.Rows.Count)).ToString();
???????????????
??????????? }
??????? }
17.GridView數據導入Excel/Excel數據讀入GridView
??? 解決方案:
??????? 頁面增加一個按鈕,單擊事件添加如下方法:
??????? protected void Button1_Click(object sender, EventArgs e)
??????????? ...{
??????????????? Export("application/ms-excel", "學生成績報表.xls");
??????????? }

???????private void Export()
????????{?
??????? Response.Charset = "GB2312";
??????? Response.ContentEncoding = System.Text.Encoding.UTF7;
??????? Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString() + ".xls");
??????? Response.ContentType = "application/ms-excel";
??????? this.EnableViewState = false;
??????? StringWriter tw = new StringWriter();
??????? HtmlTextWriter hw = new HtmlTextWriter(tw);
??????? GridView1.RenderControl(hw);
??????? Response.Write(tw.ToString());
??????? Response.End();
?????? }
??????? //如果沒有下面方法會報錯類型“GridView”的控件“GridView1”必須放在具有 runat=server 的窗體標記內
??????? public override void VerifyRenderingInServerForm(Control control){}
??????? 還要設置該屬性:EnableEventValidation="false"

只能在執行Render() 的過程中調用 RegisterForEventValidation;

在實現"將GridView中的數據導出到Excel中"的時候出現了如下錯誤: 用戶代碼未處理 InvalidOperationException
只能在執行 Render() 的過程中調用 RegisterForEventValidation;
???? EnableEventValidation屬性是 .NET Framework 2.0 中是新增的屬性,默認的情況下該屬性的值為true;通過這個新增的功能ASP.NET會檢查 POST方法中的所帶的參數,如果認為不合法,就會拋出異常。這個設計的目的是為了防止惡意用戶利用post 方法發送一些惡意數據,但是有時也會出現類似上面的錯誤。 只要禁止這個功能,問題就能得到解決。可以通過以下兩種途徑解決:
1、在Web.Config文件中:在<system.web></system.web>標記中添加如下代碼:
<system.web>
????? <pages enableEventValidation="false"> </pages>
</system.web>
2、在具體的.aspx頁面的源代碼中修改代碼,如下:
<%@ Page Language="C#" EnableEventValidation="false" AutoEventWireup="true" CodeFile="GridView_Export_Excel.aspx.cs" Inherits="GridView_Export_Excel" %>


??????? 還有由于是文件操作所以要引入名稱空間IO和Text
讀取Excel數據的代碼:這個很簡單的
private DataSet CreateDataSource()
??? ...{
??????? string strCon;
??????? strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("excel.xls") + "; Extended Properties=Excel 8.0;";
??????? OleDbConnection olecon = new OleDbConnection(strCon);
??????? OleDbDataAdapter myda = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strCon);
??????? DataSet myds = new DataSet();
??????? myda.Fill(myds);
??????? return myds;
??? }
??? protected void Button1_Click(object sender, EventArgs e)
??? ...{
??????? GridView1.DataSource = CreateDataSource();
??????? GridView1.DataBind();
??? }

18.鼠標移到GridView某一行時改變該行的背景色方法一
??? protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
??? ...{
??????? int i;
??????? //執行循環,保證每條數據都可以更新
??????? for (i = 0; i < GridView1.Rows.Count; i++)
??????? ...{
??????????? //首先判斷是否是數據行
??????????? if (e.Row.RowType == DataControlRowType.DataRow)
??????????? ...{
??????????????? //當鼠標停留時更改背景色
??????????????? e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor=''#00A9FF''");
??????????????? //當鼠標移開時還原背景色
??????????????? e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
??????????? }
??????? }

??? }
鼠標移到GridView某一行時改變該行的背景色方法二
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
??? ...{
????
??????? /**/執行循環,保證每條數據都可以更新
??????? //for (int i = 0; i < GridView1.Rows.Count; i++)
??????? //{
??????? //??? //首先判斷是否是數據行
??????? //??? if (e.Row.RowType == DataControlRowType.DataRow)
??????? //??? {
??????? //??????? //當鼠標停留時更改背景色
??????? //??????? e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor=''#00A9FF''");
??????? //??????? //當鼠標移開時還原背景色
??????? //??????? e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
??????? //??? }
??????? //}
??????? //如果是綁定數據行
??????? if (e.Row.RowType == DataControlRowType.DataRow)
??????? ...{
??????????? //鼠標經過時,行背景色變
??????????? e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=''#E6F5FA''");
??????????? //鼠標移出時,行背景色變
??????????? e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''#FFFFFF''");
??????? }

??? }

文章出處:http://www.diybl.com/course/4_webprogram/asp.net/asp_netxl/20071222/93080.html

轉載于:https://www.cnblogs.com/zhongcj/archive/2009/09/15/1566990.html

總結

以上是生活随笔為你收集整理的gridView总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。