<asp:GridView ID="resultGridView"runat="server"AutoGenerateColumns="False"Width="100%"GridLines="None"ShowFooter="True"OnRowCommand="resultGridView_RowCommand">
<Columns>
<asp:TemplateField>
【对标题的重新设定】
<HeaderTemplate>
<tablewidth="100%"border="0"cellpadding="0"cellspacing="0">
<tr>
<td>房号</td>
<td>名称</td>
<td>类型</td>
<td>建筑面积</td>
<td>使用面积</td>
<td>容纳人数</td>
<td>楼宇</td>
<td>是否使用</td>
<td>删除</td>
</tr>
</HeaderTemplate>
【实现对数据的绑定】
<ItemTemplate>
<tr>
<td><a href='#i' title='<%#Eval("RoomName") %>'【当鼠标放在上面显示的信息】 onclick="OpenWin('wp_RoomInfo_Edit.aspx?RoomID=<%# Eval("RoomID") %>')">
<%# Eval("RoomID")%></a></td>【对第一个点击时的响应】
<td><%# Eval("RoomName")%></td>
<td><%# Eval("RoomType")%></td>
<td><%# Eval("RoomJianZhuMj")%></td>
<td><%# Eval("RoomShiYongMj")%></td>
<td><%# Eval("RoomRs")%></td>
<td><%# Eval("LouYuName")%></td>
<td><%# Eval("RoomIsUse").ToString()== "True"?"是":"否" %></td>
<td><asp:LinkButton ID="lbtnDel" runat="server" CommandArgument='<%#Eval("RoomID") %>' OnClientClick="javascript:return confirm('删除,确认?')">删除</asp:LinkButton></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<tablewidth="100%"border="0"cellpadding="0"cellspacing="0">
<tr>
<td>房号</td>
<td>名称</td>
<td>类型</td>
<td>建筑面积</td>
<td>使用面积</td>
<td>容纳人数</td>
<td>楼宇</td>
<td>是否使用</td>
<td>删除</td>
</tr>
<tr>
<td colspan="9" align="center" height="200">没有数据</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
方法二:
<asp:GridView ID="resultGridView"runat="server"AutoGenerateColumns="False"Width="100%"
OnRowDeleting="resultGridView_RowDeleting"DataKeyNames="LabCenterContgTeacherId"CellPadding="5"OnRowDataBound="resultGridView_RowDataBound">【这里设置了GridView的属性,其中包括了对删除选项的 OnRowDeleting="resultGridView_RowDeleting",和当选中不同行触发的事件OnRowDataBound="resultGridView_RowDataBound"】
<Columns>
<asp:BoundField HeaderText="人员编号" DataField="LabCenterContgTeacherId">
<HeaderStyle Width="80px" />
</asp:BoundField>
<asp:BoundField HeaderText="职工号" DataField="zgh"/>【数据绑定的方法】
<asp:BoundField HeaderText="职工姓名" DataField="Zgxm"/>
<asp:BoundField HeaderText="实验中心名称" DataField="LabCenterMc"/>
<asp:BoundField HeaderText="实验工作岗位" DataField="LabWorkGangWei"/>
<asp:TemplateField>
<HeaderTemplate>操作|<asp:LinkButton ID="lbtnAdd"runat="server"OnClientClick="returnOpenWin('wp_LabCenterWorkerInfo_Edit.aspx','600px','270px')">添加</asp:LinkButton></HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbtnDel"runat="server"CausesValidation="False"CommandName="Delete"Text="删除" OnClientClick='returnConfirm("删除,确认?")'></asp:LinkButton>【这个是对删除选项的设置,这样就不用再专门去设置了】|<a
href='#i' title='编辑' onclick="OpenWin('wp_LabCenterWorkerInfo_Edit.aspx?LabCenterContgTeacherId=<%#Eval("LabCenterContgTeacherId") %>','600px','270px')">编辑</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
没有数据
</EmptyDataTemplate>
<AlternatingRowStyle BackColor="#E0E0E0" />
<RowStyle BackColor="#f5f5f5" />【对颜色的设置】
</asp:GridView>
下面是对应的aspx.cs中关于选中行改变颜色的代码:
protected voidresultGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#cdebed'");
//e.Row.Attributes.Add("onmousedown"," if(c!='#cdebed'){b=c;this.style.backgroundColor='#cdebed';c='#cdebed'}else{c=b}");
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=c");
}