日期:2014-05-17 浏览次数:20502 次
<%@ Page Language="C#" EnableViewState="true" AutoEventWireup="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> public System.Data.DataTable GetData() { System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser"); dataTable1.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32))); dataTable1.Columns.Add(new System.Data.DataColumn("Title", typeof(System.String))); for (int i = 0; i < 8; i++) { dataTable1.Rows.Add(i, "测试" + i.ToString()); } return dataTable1; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView1.DataSource = GetData(); GridView1.DataBind(); } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="False"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%#Page.ResolveUrl("~/ming/") + Eval("UserId","../dengguang-xian.aspx?id={0}") %>' Text='<%#Eval("Title").ToString().Length>10?Eval("Title").ToString().Substring(0,10)+"...":Eval("Title").ToString().Trim()+ "<font style='color:red'>" + Eval("Title").ToString() + "</font>"%>'></asp:HyperLink> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </form> </body> </html>