日期:2014-05-17 浏览次数:20477 次
<asp:GridView ID="GridView1" runat="server" Width="80%"> </asp:GridView> if (!IsPostBack) { GridView1.DataSource = dt; GridView1.DataBind(); } <%-- detail_id price quantity amount 1 320000.00000000 1.0000 320000.00 2 2000.00000000 1.0000 2000.00 3 680000.00000000 1.0000 680000.00 4 600000.60000000 1.0000 600000.60 如何让后面3列右对齐。 --%>
<%@ 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("detail_id", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("price", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("quantity", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("amount", typeof(System.String))); for (int i = 0; i < 8; i++) { dt.Rows.Add(new Object[] { "孟子章" + i.ToString(), "学生姓名" + i.ToString(), "孟子章" + i.ToString(), "学生姓名" + i.ToString() }); } return dt; } protected void Page_Load(object sender, EventArgs e) { GridView1.DataSource = this.CreateDataSourceByXianhuiMeng(); GridView1.DataBind(); GridView1.HeaderRow.Cells[GridView1.HeaderRow.Cells.Count - 1].HorizontalAlign = HorizontalAlign.Right; foreach (GridViewRow x in GridView1.Rows) { x.Cells[x.Cells.Count - 1].HorizontalAlign = HorizontalAlign.Right; x.Cells[x.Cells.Count - 2].HorizontalAlign = HorizontalAlign.Right; x.Cells[x.Cells.Count - 3].HorizontalAlign = HorizontalAlign.Right; } } </script> <html> <head> <title></title> </head> <body> <form id="form1" runat="server"> <as