如何用设置gridview
<table width="526" height="187" border="1">
<tr>
<td rowspan="2">名称</td>
<td height="38" colspan="2">成绩</td>
<td rowspan="2">总分</td>
</tr>
<tr>
<td height="23">数学</td>
<td>语文</td>
</tr>
<tr>
<td>zhangsan</td>
<td>90</td>
<td>89</td>
<td> </td>
</tr>
<tr>
<td>lisi</td>
<td>78</td>
<td>88</td>
<td> </td>
</tr>
</table>
我知道repeater能实现,不过我想知道用gridview怎么实现
这种效果是不是只能用table来实现,我觉得用table太麻烦了,几乎所有代码都得手写.... 展开
<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.head{border-left:1px solid #e8e8e8; text-align:center}
.body{border-left:1px solid #f4f4f4; border-bottom:1px solid #f4f4f4}
.input{border:1px solid #cccccc; width:80%;height:16px; padding-top:2px; padding-left:2px}
.textarea{border:1px solid #cccccc; width:80%;height:60px; padding-top:1px; padding-left:1px; overflow-y:auto}
</style>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<div style="border:1px Solid #cccccc; width:700px">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Horiz Width="100%" BorderStyle="None" BorderWidth="0px" GridLines="None" UseAccessibleHeader="False" ShowFooter="True" Font-Size="12px" DataKeyNames="ID" CellPadding="0" >
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="margin:1px 1px 0px 1px" width="100%">
<tr>
<td align="center" valign="middle" bgcolor="#f6f6f6" height="25" width="8%">编 号</td>
<td class="head" valign="middle" bgcolor="#f6f6f6" width="50%">标 题</td>
<td class="head" valign="middle" bgcolor="#f6f6f6" width="15%">添加时间</td>
<td class="head" valign="middle" bgcolor="#f6f6f6" width="15%">管 理</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="border-bottom:1px solid #f4f4f4" align="center" valign="middle" height="20"><%# Eval("ID") %></td>
<td align="left" class="body" valign="middle"> <%# Eval("Title") %></td>
<td align="center" class="body" valign="middle"><%# Eval("AddTime") %></td>
<td align="center" class="body" valign="middle">
<asp:LinkButton ID="LinkButton1" CommandName="Edit" CausesValidation="false" runat="server">编 辑</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete" CausesValidation="false">删 除</asp:LinkButton></td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td rowspan="2" style="border-bottom:1px solid #f4f4f4; color:Red;" align="center" valign="middle" height="100">编辑状态</td>
<td align="left" colspan="2" valign="middle" height="30"><asp:TextBox CssClass="input" ID="TextBox1" runat="server" Text='<%# Eval("Title") %>'></asp:TextBox></td>
<td rowspan="2" align="center" class="body" valign="middle" height="100">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Update" CausesValidation="true">更 新</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="Cancel" CausesValidation="false">取 消</asp:LinkButton></td>
</tr>
<tr>
<td height="70" colspan="2" class="body" valign="top"><asp:TextBox ID="TextBox2" runat="server" CssClass="textarea" TextMode="MultiLine" Text='<%# Eval("Content") %>'></asp:TextBox></td>
</tr>
</EditItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div style="font-size:12px; margin:3px" align="center">
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Label ID="Label2" runat="server"></asp:Label>
<asp:HyperLink ID="HyperLink1" runat="server">首 页</asp:HyperLink>
<asp:HyperLink ID="HyperLink2" runat="server">上一页</asp:HyperLink>
<asp:HyperLink ID="HyperLink3" runat="server">下一页</asp:HyperLink>
<asp:HyperLink ID="HyperLink4" runat="server">尾 页</asp:HyperLink>
</div>
</div>
</div>
</form>
</body>
</html>
程现方式如下图片
<table width="526" height="187" border="1">
<asp:Repeater ID ="repeater" DataSourceID ="你的数据源" runat ="server" >
<HeaderTemplate >
<tr>
<td rowspan="2">
名称
</td>
<td height="38" colspan="2">
成绩
</td>
<td rowspan="2">
总分
</td>
</tr>
<tr>
<td height="23">
数学
</td>
<td>
语文
</td>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td>
<%#Eval ("字段名") %>
</td>
<td>
<%#Eval ("字段名") %>
</td>
<td>
<%#Eval ("字段名") %>
</td>
<td>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>