一个简单的GridView设置复合表头问题。

 

一个简单的GridView设置复合表头问题。

2009012915112360.jpg       

 

.aspx 

ContractedBlock.gif ExpandedBlockStart.gif Code

     
<asp:GridView ID="GridView1" runat="server" CssClass="gvtab" GridLines="None" AutoGenerateColumns="False"
                                    EmptyDataText
="没有数据记录!!" AllowSorting="True" OnRowCreated="GridView1_RowCreated"
                                    OnRowDeleting
="GridView1_RowDeleting">
                                    
<AlternatingRowStyle CssClass="tr2" />
                                    
<Columns>
                                        
<asp:BoundField HeaderText="分类" DataField="G_Name" />
                                        
<asp:TemplateField HeaderText="序号" HeaderStyle-Width="5%">
                                            
<ItemTemplate>
                                                
<%# (Container.DataItemIndex+1).ToString()%>
                                                
<asp:HiddenField ID="txtID" runat="server" Value='<%# Eval("B_ID")%>' />
                                            
</ItemTemplate>
                                        
</asp:TemplateField>
                                        
<asp:BoundField HeaderText="材料名称" DataField="M_Name" />
                                        
<asp:BoundField HeaderText="图号" DataField="D_DrawingNo" />
                                        
<asp:BoundField HeaderText="规格" DataField="M_Spec" />
                                        
<asp:BoundField HeaderText="颜色" DataField="M_Color" />
                                        
<asp:BoundField HeaderText="单位" DataField="U_Name" />
                                        
<asp:BoundField HeaderText="净用量" DataField="N_WasteRate" />
                                        
<asp:BoundField HeaderText="损耗率" DataField="" />
                                        
<asp:BoundField HeaderText="合计" DataField="" />
                                        
<asp:BoundField HeaderText="单价" DataField="" />
                                        
<asp:BoundField HeaderText="金额" DataField="" />
                                        
<asp:BoundField HeaderText="备注" DataField="B_Remark" />
                                        
<asp:TemplateField HeaderText="操作" HeaderStyle-Width="25%">
                                        
<ItemTemplate>
                                       
<img alt="" height="16" src="../App_Themes/Default/Images/tab/edit.gif" width="16">
                                       
<asp:HyperLink ID="hlEdit" runat="server" Text="编辑" NavigateUrl='<%#"MaterialEdit.aspx?

                                       
Action=Edit&ID="+ Eval("B_ID")  %>' />
                                       
<img alt="" height="16" src="../App_Themes/Default/Images/tab/del.gif" width="16">
                                        
<asp:LinkButton ID="lbDel" runat="server" Text="删除" CommandName="Del" 

                                        CommandArgument
='<%#Eval("B_ID") %>'></asp:LinkButton>
                                            
</ItemTemplate>
                                        
</asp:TemplateField>
                                    
</Columns>
                                
</asp:GridView>

 .aspx.cs

ContractedBlock.gif ExpandedBlockStart.gif Code

        
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            
if (e.Row.RowType == DataControlRowType.Header)
            {
                
//第一行表头
                TableCellCollection tcHeader = e.Row.Cells;
                tcHeader[
0].Attributes.Add("rowspan""2");
                tcHeader[
1].Attributes.Add("rowspan""2");
                tcHeader[
2].Attributes.Add("rowspan""2");
                tcHeader[
3].Attributes.Add("rowspan""2");
                tcHeader[
4].Attributes.Add("rowspan""2");
                tcHeader[
5].Attributes.Add("rowspan""2");
                tcHeader[
6].Attributes.Add("rowspan""2");
                tcHeader[
7].Attributes.Add("colspan""3");
                tcHeader[
7].Text = "材料净用量";
                tcHeader[
8].Attributes.Add("rowspan""2");
                tcHeader[
8].Text = tcHeader[10].Text;
                tcHeader[
9].Attributes.Add("rowspan""2");
                tcHeader[
9].Text = tcHeader[11].Text;
                tcHeader[
10].Attributes.Add("rowspan""2");
                tcHeader[
10].Text = tcHeader[12].Text;
                tcHeader[
11].Attributes.Add("rowspan""2");
                tcHeader[
11].Text = tcHeader[13].Text + "</th></tr><tr>";

                
//第二行表头
                tcHeader[12].Text = "净用量";
                tcHeader[
12].Attributes.Add("style""width:10%;");
                tcHeader.Add(
new TableHeaderCell());
                tcHeader[
13].Text = "损耗率";
                tcHeader[
13].Attributes.Add("style""width:10%;");
                tcHeader.Add(
new TableHeaderCell());
                tcHeader[
14].Text = "合计";
                tcHeader[
14].Attributes.Add("style""width:10%;");
            }
        }

 

 

 

转载于:https://www.cnblogs.com/SissyNong/archive/2009/01/29/1381320.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值