asp.net – 为什么GridView在回发后不会将标题行呈现为标题行?
发布时间:2020-05-22 21:21:14 所属栏目:asp.Net 来源:互联网
导读:在Grid绑定之后,将TableSection = TableRowSection.TableHeader设置为最初,将标题行放在thead中.在回发(网格不重新绑定)之后,标题行还原到表格体.我期望标题行留在thead中;有人可以解释为什么不是这样或者我做错了什么? 样品: 点击按钮进行回发.在回发后,标
|
在Grid绑定之后,将TableSection = TableRowSection.TableHeader设置为最初,将标题行放在thead中.在回发(网格不重新绑定)之后,标题行还原到表格体.我期望标题行留在thead中;有人可以解释为什么不是这样或者我做错了什么? 样品: 点击按钮进行回发.在回发后,标题不是橙色,因为它不再是inad了. ASPX <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="gridtest.aspx.cs" Inherits="ffff.gridtest" %>
<!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">
<style type="text/css">
thead th { background-color:Orange;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div><asp:Button ID="Button1" runat="server" Text="Button" />
this button is here just to trigger a postback</div>
<asp:GridView ID="gv1" runat="server"></asp:GridView>
</form>
</body>
</html>
码 using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ffff
{
public partial class gridtest : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
gv1.DataBound += new EventHandler(gv1_DataBound);
if (!IsPostBack) { BindGrid(); }
}
void Page_PreRender(object sender,EventArgs e)
{
if (gv1.HeaderRow != null)
System.Diagnostics.Debug.WriteLine(gv1.HeaderRow.TableSection); // still TableHeader after postback
}
void gv1_DataBound(object sender,EventArgs e)
{
if (gv1.HeaderRow != null)
{
gv1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
private void BindGrid()
{
gv1.DataSource = this.Page.Controls;
gv1.DataBind();
}
}
}
解决方法请使用Pre_Render_Complete事件添加表部分.这将确保始终添加该部分.正如您目前在DataBound上所做的那样,只有当数据被绑定时才会添加该部分.protected override void OnPreRenderComplete(EventArgs e)
{
if (gv1.Rows.Count > 0)
{
gv1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
随意更改我用来检查标题行的行检查. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 保持viewdata在RedirectToAction
- asp.net-web-api – 在Visual Studio中启动WebAPI项目的最简
- asp.net-mvc-3 – 不能将lambda表达式转换为’string’类型
- asp.net – 如何在HTML标记中阅读web.config APP键设置
- 防止双击asp.net按钮
- asp.net-mvc-3 – 在代码MVC Razor中呈现局部视图
- asp.net – 当绑定值包含冒号时,如何绑定GridView HyperLin
- asp.net/C#中的请求来源
- asp.net 读取并修改config文件实现代码
- .net – 设置可用于AppFabric缓存的内存量
推荐文章
站长推荐
热点阅读
