怎样给asp:gridview自动生成的div 添加样式 或去除其div,急??

luodiweichen19861225 2012-06-27 03:48:26
动态从库里面去了数据,结果发现除了生成表之外,还默认生成一个div,怎么操作其div,给他加样式表?
...全文
435 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
indentify 2013-09-29
  • 打赏
  • 举报
回复
这两天我也遇到这样的问题 在网上搜索了一下,最简单的解决办法是把gridview的width属性设置为100%就行了
skk5529765 2012-09-24
  • 打赏
  • 举报
回复
兄弟你这问题解决了没啊
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 的回复:]
我下班了,可我不能走!
[/Quote]
好可怜,那就等老板发话吧。呵呵..
xb12369 2012-06-27
  • 打赏
  • 举报
回复
我下班了,可我不能走!
lizhengdao1314 2012-06-27
  • 打赏
  • 举报
回复
在你的GridView后面写JS试试控制它的样式,如Jquery可这样写:$("#GridView1").parent().css({border:"1px #ff0000 solid",padding:5});
zhaojm0405 2012-06-27
  • 打赏
  • 举报
回复
可以设法对你生成的div加点特别的,比如在加个div 标注id,这样不就好定义css了么
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]
没法控制和去掉的

变通方法1

<div id=x>
<asp:GridView

css里面写
#x div{}
就可以了。


变通方法2
换其他控件。
[/Quote]

方法一试过了,方法二不可取,关键是实在不知道其他控件怎么用(要在别人定义好的框架里面改动),现在情况是有想法没出路....
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]
不去掉对你有什么影响吗?
[/Quote]

要么不要,要么给他添加样式,我目的是为了固定列头,要固定的这一列是从数据库查出来的Id项。要实现对动态数据列头的控制。
孟子E章 2012-06-27
  • 打赏
  • 举报
回复
不去掉对你有什么影响吗?
孟子E章 2012-06-27
  • 打赏
  • 举报
回复
没法控制和去掉的

变通方法1

<div id=x>
<asp:GridView

css里面写
#x div{}
就可以了。


变通方法2
换其他控件。
  • 打赏
  • 举报
回复
<asp:GridView ID="GridView1" SkinID="GridView1" style="width:1500px;" DataKeyNames="zrzt" ShowHeader="false" runat="server" onrowdatabound="GridView1_RowDataBound">
<RowStyle BackColor="#ECF5FF" ForeColor="Black" />
<Columns>
<asp:TemplateField >
<ItemTemplate>
<font color="#000000" style="font-size: 11px">
<%# Container.DataItemIndex + 1 %>
</font>
</ItemTemplate>
<ItemStyle Height="25px" Width="3%" HorizontalAlign="Center" />
<HeaderStyle Width="3%" Height="25px" HorizontalAlign="Center" />
</asp:TemplateField>


在asp文件查看,源码是上面这样的,在html文件查看,
<div>主要在这) <table cellspacing="0" cellpadding="4" rules="all" border="1" id="GridView1" style="color:Black;background-color:White;border-color:#CCCCCC;border-width:1px;border-style:None;width:100%;border-collapse:collapse;width:1500px;">
<tr onmouseover="currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFFF80',this.style.fontWeight='';" onmouseout="this.style.backgroundColor=currentcolor,this.style.fontWeight='';" onclick="this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';" style="color:Black;background-color:#ECF5FF;">
<td align="center" style="height:25px;width:3%;">
<font color="#000000" style="font-size: 11px">
1
</font>
</td><td align="center" style="height:25px;width:6%;">
<font color="#000000" style="font-size: 11px">
发改委
</font>
</td>
gzpepco 2012-06-27
  • 打赏
  • 举报
回复
那你无视他不就行了?多了个div外套对布局不会有影响吧??

[Quote=引用 7 楼 的回复:]


我根本就没打算让它生成div,如果他不生成,我就不用给他加样式了.....还有,我是帮人家改程序,asp我一点都没学过。别的更不会用..
[/Quote]
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
你可以
<div id=x>
<asp:GridView

css里面写
#x div{}
就可以了。
[/Quote]

我根本就没打算让它生成div,如果他不生成,我就不用给他加样式了.....还有,我是帮人家改程序,asp我一点都没学过。别的更不会用..
孟子E章 2012-06-27
  • 打赏
  • 举报
回复
你要是特别纠结这个,就采用其他控件如ListView,Repeater
孟子E章 2012-06-27
  • 打赏
  • 举报
回复
你可以
<div id=x>
<asp:GridView

css里面写
#x div{}
就可以了。
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
可以设置默认的div{padding:0;margin:0}

或者采用其他控件如ListView,Repeater
[/Quote]


关键是自动生成的div 没有Id ,格式就这样<div> 我是把它另存为html文件后看到的,在<asp:gridview>源文件中看不到,所以没法操作...
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
记录下div的id然后生成样式就好了咯。。
话说gridview的样式 是可以调整的啊- -
[/Quote]

关键是自动生成的div 没有Id ,格式就这样<div> 我是把它另存为html文件后看到的...
xmhxjjq 2012-06-27
  • 打赏
  • 举报
回复
记录下div的id然后生成样式就好了咯。。
话说gridview的样式 是可以调整的啊- -
孟子E章 2012-06-27
  • 打赏
  • 举报
回复
可以设置默认的div{padding:0;margin:0}

或者采用其他控件如ListView,Repeater
ASP.NET实现Gridview隐藏/显示列源码 介绍: 这篇文章演示如果让用户有显示/隐藏他们需要的GridView的列的功能,这是非常有用的,因为在GridView的所有列并不是每个的用户都需要的.用户想根据自己的需求看到想要的列.而不是显示一个巨大的gridview,霸占了整个屏幕,而是一个整洁的Gridview,而且它有所有你需要的列.对于页面的打印这也是一个非常有用的技术,因为用户可以灵活地选择GridView的列打印。 背景: RowCreated 和ItemDataBound 事件允许你用多种方式注入HTML, CSS,和JavaScript 来增强GridView 控件的功能。 文章将会演示两种显示和隐藏GridView列的方法,一种是客户端的方法,另外一种是服务段的方法. 在客户段显示和隐藏GridView的列 大部分代码是在GridView的RowCreated事件生成客户端的功能的。当GridView的Header行被创建后,一个带负号的HyperLink被插入每个Header行的单元格中用来隐藏列。 这个hyperlink通过它的onclick事件调用一个HideCol的Javascript方法,CSS类用来增加负号的大小,当每个数据行被创建的时候,一个Id将会被添加到每行中用来让Javascript区分每一行. 代码 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { GridView gridView = (GridView)sender; StringBuilder sb = new StringBuilder(); // For the header row add a link to each header // cell which can call the HideCol javascript method if (e.Row.RowType == DataControlRowType.Header) { // Loop through each cell of the row for (int columnIndex = 0; columnIndex 0) { Label columnTextLabel = new Label(); columnTextLabel.Text = e.Row.Cells[columnIndex].Text; e.Row.Cells[columnIndex].Controls.Add(columnTextLabel); } } } // Give each row an id if (e.Row.RowType == DataControlRowType.Pager) e.Row.Attributes.Add("id", gridView.ClientID + "_pager"); else e.Row.Attributes.Add("id", gridView.ClientID + "_r" + e.Row.RowIndex.ToString()); } SetupShowHideColumns方法中生成“Show Columns”下拉菜单的HTML,输出在Literal控件上面 。 代码 private void SetupShowHideColumns(GridView gridView, Literal showHideColumnsLiteral) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append("- Show Column -"); showHideColumnsLiteral.Text = sb.ToString(); } 在数据绑定到GridView之后,其余的工作由ShowHideColumns.js中的javascript来完成.当列头的hyperlink被点击的时候后,它将会传递GridView的名字,列的索引和列名给HideCol方法,这个方法能找到这一列的每个单元格,每个单元格的将添加display:none样式,用来隐藏这一列. 当选择"Show Column"中的选项后,Javascript方法ShowCol将会被调用,它将移除每个单元格的display:none样式,这一列将会被再次显示. 在服务端显示/隐藏GridView的列 服务端的例子将通过RowCreated事件给每个列头添加一个负号,这次是使用LinkButton控件.设置CommandName和CommandArgument属性,这样当通过LinkButton引发RowCommand事件时,相关的列都可以隐藏。以前隐藏的列索引存储在一个List中,这些列在建立时,将会被隐藏的。 代码 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { // For the header row add a link button to each header // cell which can execute a row command if (e.Row.RowType == DataControlRowType.Header) { // Loop through each cell of the header row for (int columnIndex = 0; columnIndex 0) { Label columnTextLabel = new Label(); columnTextLabel.Text = e.Row.Cells[columnIndex].Text; e.Row.Cells[columnIndex].Controls.Add(columnTextLabel); } } } // Hide the column indexes which have been stored in hiddenColumnIndexes foreach(int columnIndex in hiddenColumnIndexes) if (columnIndex 0) { this.GridView1ShowHideColumns.Visible = true; this.GridView1ShowHideColumns.Items.Add(new ListItem("-Show Column-", "-1")); foreach (int i in hiddenColumnIndexes) this.GridView1ShowHideColumns.Items.Add( new ListItem(columnNames[i], i.ToString())); } else { this.GridView1ShowHideColumns.Visible = false; } } 示例项目的例子: 客户端的例子: •C#.NET - Client-side example accessing data stored in session. •C#.NET - Client-side example which includes: MasterPage, UpdatePanel, GridView editing, paging and sorting, accessing data via the SqlDataSource control. •VB.NET - Client-side example accessing data stored in session. 服务端的例子 •C#.NET - Server-side example accessing data stored in session. •C#.NET - Server-side example which includes: MasterPage, UpdatePanel, GridView editing, paging and sorting, accessing data via the SqlDataSource control. •VB.NET - Server-side example accessing data stored in session. 结论: 如果你想让你的用户能够显示和隐藏在ASP.NET GridView的列,那么这种技术可能是非常有用的。 原文:http://www.codeproject.com/KB/webforms/ShowHideGridviewColumns.aspx 作者:朱祁林 出处:http://zhuqil.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 无限级菜单显示
<div>
<asp:TreeView ID="trv_menu" runat="server" Font-Bold="False" Font-Size="12px" Width="150px" OnSelectedNodeChanged="trv_menu_SelectedNodeChanged" ShowLines="True" AutoGenerateDataBindings="False"> asp:TreeView>
<asp:Label ID="lbl_nodeText" runat="server" Font-Size="12px">asp:Label>  <asp:Label ID="lbl_nodeValue" runat="server" Font-Size="12px">asp:Label> <div style=" height:28px"> <asp:Label ID="Label1" runat="server" Font-Size="12px" Text="目录名称:">asp:Label> <asp:TextBox ID="txt_menu" runat="server" Font-Size="12px">asp:TextBox> * <asp:Button ID="btn_Add" runat="server" Font-Size="12px" OnClick="btn_Add_Click" Text="添加" /> div>
<asp:GridView ID="grd_menu" runat="server" AutoGenerateColumns="False" CellPadding="3" DataKeyNames="ID" Font-Size="12px" Width="100%" BorderWidth="1px" OnRowCancelingEdit="grd_menu_RowCancelingEdit" OnRowDeleting="grd_menu_RowDeleting" OnRowEditing="grd_menu_RowEditing" onrowdatabound="grd_menu_RowDataBound" onrowupdating="grd_menu_RowUpdating"> <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" /> <asp:BoundField DataField="content" HeaderText="栏目名称" /> <asp:CommandField HeaderText="编辑" ShowEditButton="True" /> <asp:CommandField HeaderText="删除" ShowDeleteButton="True" /> asp:GridView
div>
党校在线考试系统,自行判分,随机抽题 <%@ Page Title="" Language="C#" MasterPageFile="~/HouAdmin/MasterPage.master" AutoEventWireup="true" CodeFile="admin.aspx.cs" Inherits="HouAdmin_admin" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div style="height: 100%">
<asp:Label ID="Label1" runat="server" Text="查询条件" Font-Size="9pt">asp:Label> <asp:DropDownList ID="ddlAdminName" runat="server" Width="107px" Font-Size="9pt"> <asp:ListItem Value="Name">管理员名称asp:ListItem> asp:DropDownList> <asp:Label ID="Label2" runat="server" Text="关键字" Font-Size="9pt">asp:Label> <asp:TextBox ID="txtSelect" runat="server" Width="100px" Font-Size="9pt">asp:TextBox> <asp:Button ID="btnSelect" runat="server" Text="查询" OnClick="Button1_Click" Font-Size="9pt" /> <asp:LinkButton ID="LinkButton10" runat="server" OnClick="LinkButton10_Click" Font-Size="9pt" Font-Underline="False">添加管理员asp:LinkButton>

<asp:GridView ID="gvAdminInfo" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" Width="550px" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="5" OnRowDeleting="GridView1_RowDeleting" Font-Size="9pt" OnRowDataBound="GridView1_RowDataBound" HorizontalAlign="Center"> <asp:BoundField DataField="Name" HeaderText="管理员名称"> asp:BoundField> <asp:BoundField DataField="PWD" HeaderText="管理员密码" /> <asp:BoundField DataField="JoinTime" HeaderText="加入时间" /> <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="admin_update.aspx?ID={0}" HeaderText="修改" Text="修改"> asp:HyperLinkField> <asp:CommandField HeaderText="删除" ShowDeleteButton="True"> asp:CommandField> asp:GridView> div> asp:Content>

62,071

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧