标签:style blog http color java os 使用 io strong
继续看一个简单的ASP.NET应用。<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body id="Body1" runat="server"> <form id="Form1" runat="server"> <asp:GridView ID="dgPersons" runat="server" EnableViewState="false" CellPadding="4" GridLines="Horizontal" PageChange="TextBox" AutoGenerateColumns="False" SortMode="Total" ForeColor="#333333" CellSpacing="1" Width="60%" ShowNoRecordTip="True" OnRowCreated="DgPersons_RowCreated"> <Columns> <asp:TemplateField> <ItemTemplate> <%#Container.DataItemIndex +1%> <input id="hideID" type="hidden" runat="server" value=‘<%#Eval("p_id")%>‘ /> </ItemTemplate> <HeaderTemplate> <span>序号</span> </HeaderTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <span> <%#Eval("p_name")%></span> </ItemTemplate> <HeaderTemplate> <span>姓名</span> </HeaderTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <span> <%#Eval("p_age")%></span> </ItemTemplate> <HeaderTemplate> <span>年龄</span> </HeaderTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <span> <%#Eval("p_sex")%></span> </ItemTemplate> <HeaderTemplate> <span>性别</span> </HeaderTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <span> <%#Eval("p_industry")%></span> </ItemTemplate> <HeaderTemplate> <span>行业</span> </HeaderTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <span> <%#Eval("p_job")%></span> </ItemTemplate> <HeaderTemplate> <span>职业</span> </HeaderTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <span> <%#Eval("p_experience")%></span> </ItemTemplate> <HeaderTemplate> <span>经验</span> </HeaderTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" HorizontalAlign="Center" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <RowStyle HorizontalAlign="Center" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#999999" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> </asp:GridView> </form> </body> <script type="text/javascript" src="../Scripts/Ajax.js"></script> <script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script> <script language="javascript" type="text/javascript"> var dgPersonsID = "<%= dgPersons.ClientID %>"; </script> </html>虽然显示时,前台设置的表头最终没有显示,不过还是要写的,因为免得自己记不清了,再有列项还需要绑定数据的。
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = InitData(); this.dgPersons.DataSource = dt; this.dgPersons.DataBind(); } } private DataTable InitData() { DataTable PersonCollect = new DataTable(); PersonCollect = new DataTable(); PersonCollect.Columns.Add("p_id"); PersonCollect.Columns.Add("p_name"); PersonCollect.Columns.Add("p_age"); PersonCollect.Columns.Add("p_sex"); PersonCollect.Columns.Add("p_industry"); PersonCollect.Columns.Add("p_job"); PersonCollect.Columns.Add("p_experience"); if (PersonCollect.Rows.Count < 1) { for (int i = 0; i < 10; i++) { DataRow nrow = PersonCollect.NewRow(); nrow["p_id"] = System.Guid.NewGuid().ToString(); nrow["p_name"] = "西北白杨树"; nrow["p_age"] = 27; nrow["p_sex"] = "男"; nrow["p_industry"] = "软件"; nrow["p_job"] = "高级工程师"; nrow["p_experience"] = "若干年"; PersonCollect.Rows.Add(nrow); } } return PersonCollect; } protected void DgPersons_RowCreated(object sender, GridViewRowEventArgs e) { switch (e.Row.RowType) { case DataControlRowType.Header://行是标题行 TableCellCollection personHeader = e.Row.Cells;//标题行的单元格集合 personHeader.Clear();//清空 //添加一个表头 比如以及表头有三列 那么序号就是 0 1 2 personHeader.Add(new TableHeaderCell()); personHeader[0].Attributes.Add("rowspan", "2"); //跨2行 personHeader[0].Attributes.Add("colspan", "1"); //跨1列 personHeader[0].Attributes.Add("bgcolor", "DarkGreen"); personHeader[0].Text = "序号"; personHeader.Add(new TableHeaderCell()); personHeader[1].Attributes.Add("colspan", "3"); //跨3列 personHeader[1].Attributes.Add("bgcolor", "DarkYellow"); personHeader[1].Text = "个人基本信息"; personHeader.Add(new TableHeaderCell()); personHeader[2].Attributes.Add("colspan", "3"); //跨3列 personHeader[2].Attributes.Add("bgcolor", "DarkBlue"); personHeader[2].Text = "工作信息</th></tr><tr>"; //再添加一个表头 personHeader.Add(new TableHeaderCell()); personHeader[3].Attributes.Add("bgcolor", "Khaki"); personHeader[3].Text = "姓名"; personHeader.Add(new TableHeaderCell()); personHeader[4].Attributes.Add("bgcolor", "Khaki"); personHeader[4].Text = "年龄"; personHeader.Add(new TableHeaderCell()); personHeader[5].Attributes.Add("bgcolor", "Khaki"); personHeader[5].Text = "性别"; personHeader.Add(new TableHeaderCell()); personHeader[6].Attributes.Add("bgcolor", "Khaki"); personHeader[6].Text = "行业"; personHeader.Add(new TableHeaderCell()); personHeader[7].Attributes.Add("bgcolor", "Khaki"); personHeader[7].Text = "职业"; personHeader.Add(new TableHeaderCell()); personHeader[8].Attributes.Add("bgcolor", "Khaki"); personHeader[8].Text = "经验"; //还可以继续添加 //记住不论多少行表头,每个列的序号是一次递增的,而且需要换行 —</th></tr><tr> break; } }
标签:style blog http color java os 使用 io strong
原文地址:http://blog.csdn.net/yysyangyangyangshan/article/details/38807287