日期:2014-05-17 浏览次数:20524 次
<%@ Page Language="C#" EnableViewState="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> // 计算数据,完全可以从数据库取得 System.Data.DataTable CreateDataSourceByXianhuiMeng() { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(new System.Data.DataColumn("Id", typeof(System.Int32))); dt.Columns.Add(new System.Data.DataColumn("State", typeof(System.String))); for (int i = 0; i < 8; i++) { dt.Rows.Add(new Object[] { i, i.ToString() }); } return dt; } protected void Page_Load(object sender, EventArgs e) { GridView1.DataSource = this.CreateDataSourceByXianhuiMeng(); GridView1.DataBind(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { String State = DataBinder.Eval(e.Row.DataItem, "State").ToString(); HyperLink h = e.Row.Cells[1].Controls[0] as HyperLink; if (State.Equals("2")) { h.Visible = false; } } } </script> <html> <head> <title></title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="id" HeaderText="测试的" /> <asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="show.aspx?id={0}" DataTextField="State" /> </Columns> </asp:GridView> </form> </body> </html>