怎样给asp:gridview自动生成的div 添加样式 或去除其div,急?? 动态从库里面去了数据,结果发现除了生成表之外,还默认生成一个div,怎么操作其div,给他加样式表? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 net_lover 于 2012-06-27 16:20:12 编辑 记录下div的id然后生成样式就好了咯。。 话说gridview的样式 是可以调整的啊- - 关键是自动生成的div 没有Id ,格式就这样<div> 我是把它另存为html文件后看到的... 关键是自动生成的div 没有Id ,格式就这样<div> 我是把它另存为html文件后看到的,在<asp:gridview>源文件中看不到,所以没法操作... 你可以<div id=x><asp:GridViewcss里面写#x div{}就可以了。 你要是特别纠结这个,就采用其他控件如ListView,Repeater 我根本就没打算让它生成div,如果他不生成,我就不用给他加样式了.....还有,我是帮人家改程序,asp我一点都没学过。别的更不会用.. 那你无视他不就行了?多了个div外套对布局不会有影响吧?? <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> 没法控制和去掉的变通方法1<div id=x><asp:GridViewcss里面写#x div{}就可以了。变通方法2换其他控件。 可以设法对你生成的div加点特别的,比如在加个div 标注id,这样不就好定义css了么 在你的GridView后面写JS试试控制它的样式,如Jquery可这样写:$("#GridView1").parent().css({border:"1px #ff0000 solid",padding:5}); 这两天我也遇到这样的问题在网上搜索了一下,最简单的解决办法是把gridview的width属性设置为100%就行了 web services如何调用dll文件 500分求<<programing .net components>>随书光盘内容。 如何通过asp.net将ACCESS数据库里的2张表导入到SQLserver数据库里 如何给ListBox或Select控件添加时间啊??? 翻动100万级的数据 —— 后续篇 在IE中打开EXCEL 的问题 怎样删除给定值的XML文档中的对应节点 关于SQL的一个问题,求解,急,万分感谢 请问做ASP.NET的前台页面你们一般用什么做呀,.我用DREAMWAVE,可是不太理想 还是二进制的问题,已经花了300分了,高手请进(结帖率100%,在线等!!!) 样式问题 帮忙考虑下兼容性- - 在网页理嵌入音频播放器
话说gridview的样式 是可以调整的啊- -
关键是自动生成的div 没有Id ,格式就这样<div> 我是把它另存为html文件后看到的...
<div id=x>
<asp:GridViewcss里面写
#x div{}
就可以了。
我根本就没打算让它生成div,如果他不生成,我就不用给他加样式了.....还有,我是帮人家改程序,asp我一点都没学过。别的更不会用..
<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>
<asp:GridViewcss里面写
#x div{}
就可以了。
变通方法2
换其他控件。
在网上搜索了一下,最简单的解决办法是把gridview的width属性设置为100%就行了