代码如下
前台
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
后台
string value = "安监局非拉我了房间了瓦房级啊微积分书法家历史的积分我覅见";
string tmp = string.Empty;
DataTable dt = new DataTable();
for (int i = 0; i < 20; i++)
{
tmp = value.Substring((new Random()).Next(10), (new Random()).Next(value.Length - 10));
if (tmp.Equals(string.Empty))
{
i--;
continue;
}
if (!dt.Columns.Contains(tmp))
dt.Columns.Add(tmp);
else
i--;
}
dt.Rows.Add();
GridView1.DataSource = dt;
GridView1.DataBind();解释下,列是动态的。
运行就知道,会很丑,谁有好的列宽设置解决方案吗。由于数据量很大,希望尽量不要在DataBind中写算法。
前台
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
后台
string value = "安监局非拉我了房间了瓦房级啊微积分书法家历史的积分我覅见";
string tmp = string.Empty;
DataTable dt = new DataTable();
for (int i = 0; i < 20; i++)
{
tmp = value.Substring((new Random()).Next(10), (new Random()).Next(value.Length - 10));
if (tmp.Equals(string.Empty))
{
i--;
continue;
}
if (!dt.Columns.Contains(tmp))
dt.Columns.Add(tmp);
else
i--;
}
dt.Rows.Add();
GridView1.DataSource = dt;
GridView1.DataBind();解释下,列是动态的。
运行就知道,会很丑,谁有好的列宽设置解决方案吗。由于数据量很大,希望尽量不要在DataBind中写算法。
解决方案 »
- 在后台添加,JS 广告代码,首页展示!
- 问个大概框架问题。
- 用C#如何提取网页中的flash中第一张图片
- 怎么样动态添加gridview数据呢?
- webBrowser使用的问题,谢谢
- 在 <script type="text/jscript"> </script> 怎么取得DataGrid控件选择的行的ID,已经绑定DataKeyField="ID"
- SQL数据库查询问题..急急急...在线等!!!!!!!!
- 非常常见的数据转换但实现麻烦的问题?
- datagrid发生了databind()事件就一定会发生它的itemcreated事件吗?
- 我写的上传程序为何上传不了呢,麻烦帮我看看,多谢了!
- JavaScript alert问题
- 页面设计和用户体验问题,聆听高手指导!!!
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.STYLE1 {font-size: 12px}
.STYLE3 {font-size: 12px; font-weight: bold; }
.STYLE4 {
color: #03515d;
font-size: 12px;
}
-->
</style>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6">
<tr>
<td colspan="4" rowspan="3" bgcolor="#FFFFFF">
<span class="STYLE1">
你的GridView
</span>
</td>
</tr>
</table>
这样就会发现你的
GridView
变美观了!
提供一个思路,样式可以自己设置!
<style>
#GridView1 tr td:first-child { width: auto } /* 控制第1列宽度 */
#GridView1 tr td:first-child+td { width: auto } /* 控制第2列宽度 */
#GridView1 tr td:first-child+td+td { width: auto } /* 控制第3列宽度 */
#GridView1 tr td:first-child+td+td+td { width: auto } /* 控制第4列宽度 */
#GridView1 tr td:first-child+td+td+td+td { width: auto } /* 控制第5列宽度 */
#GridView1 tr td:first-child+td+td+td+td+td { width: auto } /* 控制第6列宽度 */
</style>
或使用Itemplate