在gridview的header中添加新行
来源:互联网 发布:ffmpeg下载Linux 编辑:程序博客网 时间:2024/05/16 18:28
<asp:GridView id="GridView2" runat="server" Width="100%" AutoGenerateColumns="False"
ShowHeader="false" OnRowDataBound="GridView2_RowDataBound"
OnRowCreated="GridView2_RowCreated">
<Columns >
<asp:BoundField DataField="name" HeaderText="Name"
SortExpression="name" >
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="address" HeaderText="Address"
SortExpression="address">
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="phone" HeaderText="Phone" SortExpression="phone">
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
</Columns>
</asp:GridView>
<table runat="server" id="tab_lab_def" visible="false">
<tr>
<td style="height: 21px">
1</td>
<td style="height: 21px"> New line1
</td>
<td style="height: 21px">
First Name
</td>
</tr>
<tr>
<td>
2</td>
<td>
New line2 </td>
<td>
Last Name
</td>
</tr>
<tr>
<td>
3</td>
<td>
New line3 </td>
<td>
ALL Name
</td>
</tr>
</table>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//显示GridView2 它会隐藏老header添加新3行header(从前台tab_lab_def中提取的内容
作为header)
}
}
protected void GridView2_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header,
DataControlRowState.Normal);
TableHeaderCell cell;
for (int i = 1; i < tab_lab_def.Rows.Count; i++)
{
cell = new TableHeaderCell();
cell.HorizontalAlign = HorizontalAlign.Left;
cell.Text = tab_lab_def.Rows[i].Cells[0].InnerText.Trim();
rowHeader.Cells.Add(cell);
}
((GridView)sender).Controls[0].Controls.AddAt(0, rowHeader);
rowHeader = new GridViewRow(1, 1, DataControlRowType.Header,
DataControlRowState.Normal);
for (int j = 1; j < tab_lab_def.Rows.Count; j++)
{
cell = new TableHeaderCell();
cell.HorizontalAlign = HorizontalAlign.Left;
cell.Text = tab_lab_def.Rows[j].Cells[1].InnerText.Trim();
rowHeader.Cells.Add(cell);
}
((GridView)sender).Controls[0].Controls.AddAt(1, rowHeader);
rowHeader = new GridViewRow(2, 2, DataControlRowType.Header,
DataControlRowState.Normal);
for (int k = 1; k < tab_lab_def.Rows.Count; k++)
{
cell = new TableHeaderCell();
cell.HorizontalAlign = HorizontalAlign.Left;
cell.Text = tab_lab_def.Rows[k].Cells[2].InnerText.Trim();
rowHeader.Cells.Add(cell);
}
((GridView)sender).Controls[0].Controls.AddAt(2, rowHeader);
}
}
- 在gridview的header中添加新行
- 在GridView表中添加新行
- 可以添加Footer和Header的GridView
- 在header中添加LOGO
- 在GridView中添加一行(新行) 如统计信息等
- 关于gridview添加header造成header显示不完全的解决方法
- 在jquery的ajax中添加自定义的header信息
- 在FILE_OP中添加新的操作
- 在uboot中添加新的命令
- 在caffe中添加新的层
- 在caffe中添加新的layer
- 在dataset中添加新行
- 如何在gridview的脚本添加一行添加输入行
- 在gridview中动态的添加复选框checkbox
- 用javascript实现在表格中添加新行的同时添加内容
- GridView:在EmptyTemplate中增加新记录
- ]在GridView中插入新记录
- [翻译]在GridView中插入新记录
- 分享我的电子藏书:嵌入式系列(共25本)
- Web Security Dojo v0.2 released
- SEO
- 软件视频会议技术已能承受完美性的挑剔
- php链接数据库时设置编码SET NAMES UTF8不能用UTF-8
- 在gridview的header中添加新行
- 分享我的电子藏书:数据库系列(共12本)
- ExecuteReader()、ExecuteNonQuery()和ExecuteScalar()有什么区别?
- GetClientRect, GetWindowRect
- 分享我的电子藏书:职业素养系列(共27本)
- j2me中的网络连接 request response
- 数据库水平切分的实现原理解析-分库,分表,主从,集群,负载均衡器
- C++编程思想(卷二):异常处理
- 让Ubuntu下的eclipse支持GBK编码