合併Gridview表頭
重建表頭,數據綁定後可見為.
Code
1 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
2 {
3 if (e.Row.RowType == DataControlRowType.Header)
4 {
5 TableCellCollection tcl = e.Row.Cells;
6 //清除自动生成的表头
7 tcl.Clear();
8 //添加新的表头
9 tcl.Add(new TableHeaderCell());
10 tcl[0].RowSpan = 2;
11 tcl[0].Text = "序号";
12 tcl.Add(new TableHeaderCell());
13 tcl[1].RowSpan = 2;
14 tcl[1].Text = "区域";
15 tcl.Add(new TableHeaderCell());
16 tcl[2].RowSpan = 2;
17 tcl[2].Text = "已被抽中数量";
18 tcl.Add(new TableHeaderCell());
19 tcl[3].RowSpan = 2;
20 tcl[3].Text = "送检数量";
21 tcl.Add(new TableHeaderCell());
22 tcl[4].ColumnSpan = 3;
23 tcl[4].Text = "送检数情况";
24 tcl.Add(new TableHeaderCell());
25 tcl[5].RowSpan = 2;
26 tcl[5].Text = "未送检数量";
27 tcl.Add(new TableHeaderCell());
28 tcl[6].ColumnSpan = 3;
29 tcl[6].Text = "未送检数情况</th></tr><tr><th>合格</th><th>不合格</th><th>处理中</th><th>合格</th><th>不合格</th><th>处理中";
30
31
32 }
33 }
1 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
2 {
3 if (e.Row.RowType == DataControlRowType.Header)
4 {
5 TableCellCollection tcl = e.Row.Cells;
6 //清除自动生成的表头
7 tcl.Clear();
8 //添加新的表头
9 tcl.Add(new TableHeaderCell());
10 tcl[0].RowSpan = 2;
11 tcl[0].Text = "序号";
12 tcl.Add(new TableHeaderCell());
13 tcl[1].RowSpan = 2;
14 tcl[1].Text = "区域";
15 tcl.Add(new TableHeaderCell());
16 tcl[2].RowSpan = 2;
17 tcl[2].Text = "已被抽中数量";
18 tcl.Add(new TableHeaderCell());
19 tcl[3].RowSpan = 2;
20 tcl[3].Text = "送检数量";
21 tcl.Add(new TableHeaderCell());
22 tcl[4].ColumnSpan = 3;
23 tcl[4].Text = "送检数情况";
24 tcl.Add(new TableHeaderCell());
25 tcl[5].RowSpan = 2;
26 tcl[5].Text = "未送检数量";
27 tcl.Add(new TableHeaderCell());
28 tcl[6].ColumnSpan = 3;
29 tcl[6].Text = "未送检数情况</th></tr><tr><th>合格</th><th>不合格</th><th>处理中</th><th>合格</th><th>不合格</th><th>处理中";
30
31
32 }
33 }
Code
1 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCreated="GridView1_RowCreated">
2 <Columns>
3 <asp:TemplateField HeaderText="序号">
4 <ItemTemplate>
5 <asp:Label ID="Lb_SNum" runat="server" Text='<%#Container.DataItemIndex + 1 %>'></asp:Label>
6 </ItemTemplate>
7 <ItemStyle HorizontalAlign="Center" Width="5%" Wrap="False" />
8 <HeaderStyle HorizontalAlign="Center" Wrap="False" />
9 </asp:TemplateField>
10 <asp:TemplateField HeaderText="区域" >
11 <EditItemTemplate>
12 <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Re_CName") %>'></asp:TextBox>
13 </EditItemTemplate>
14 <ItemTemplate>
15 <asp:Label ID="Label1" runat="server" Text='<%# Bind("Re_CName") %>'></asp:Label>
16 </ItemTemplate>
17 </asp:TemplateField>
18 <asp:TemplateField HeaderText="已被抽中数量">
19 <EditItemTemplate>
20 <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("czqty") %>'></asp:TextBox>
21 </EditItemTemplate>
22 <ItemTemplate>
23 <asp:Label ID="Label2" runat="server" Text='<%# Bind("czqty") %>'></asp:Label>
24 </ItemTemplate>
25 </asp:TemplateField>
26 <asp:TemplateField HeaderText="送检数量">
27 <EditItemTemplate>
28 <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("sjqty") %>'></asp:TextBox>
29 </EditItemTemplate>
30 <ItemTemplate>
31 <asp:Label ID="Label3" runat="server" Text='<%# Bind("sjqty") %>'></asp:Label>
32 </ItemTemplate>
33 </asp:TemplateField>
34 <asp:TemplateField HeaderText="合格">
35 <EditItemTemplate>
36 <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
37 </EditItemTemplate>
38 <ItemTemplate>
39 <asp:Label ID="Label4" runat="server" Text='<%# Bind("yHGqty") %>'></asp:Label>
40 </ItemTemplate>
41 </asp:TemplateField>
42 <asp:TemplateField HeaderText="不合格">
43 <EditItemTemplate>
44 <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
45 </EditItemTemplate>
46 <ItemTemplate>
47 <asp:Label ID="Label5" runat="server" Text='<%# Bind("yBHGqty") %>'></asp:Label>
48 </ItemTemplate>
49 </asp:TemplateField>
50 <asp:TemplateField HeaderText="处理中">
51 <EditItemTemplate>
52 <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
53 </EditItemTemplate>
54 <ItemTemplate>
55 <asp:Label ID="Label6" runat="server" Text='<%# Bind("yCLZqty") %>'></asp:Label>
56 </ItemTemplate>
57 </asp:TemplateField>
58 <asp:TemplateField HeaderText="未送检数量">
59 <EditItemTemplate>
60 <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("wsjqty") %>'></asp:TextBox>
61 </EditItemTemplate>
62 <ItemTemplate>
63 <asp:Label ID="Label3" runat="server" Text='<%# Bind("wsjqty") %>'></asp:Label>
64 </ItemTemplate>
65 </asp:TemplateField>
66 <asp:TemplateField HeaderText="合格">
67 <EditItemTemplate>
68 <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
69 </EditItemTemplate>
70 <ItemTemplate>
71 <asp:Label ID="Label4" runat="server" Text='<%# Bind("HGqty") %>'></asp:Label>
72 </ItemTemplate>
73 </asp:TemplateField>
74 <asp:TemplateField HeaderText="不合格">
75 <EditItemTemplate>
76 <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
77 </EditItemTemplate>
78 <ItemTemplate>
79 <asp:Label ID="Label5" runat="server" Text='<%# Bind("BHGqty") %>'></asp:Label>
80 </ItemTemplate>
81 </asp:TemplateField>
82 <asp:TemplateField HeaderText="处理中">
83 <EditItemTemplate>
84 <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
85 </EditItemTemplate>
86 <ItemTemplate>
87 <asp:Label ID="Label6" runat="server" Text='<%# Bind("CLZqty") %>'></asp:Label>
88 </ItemTemplate>
89 </asp:TemplateField>
90 </Columns>
91 </asp:GridView>
1 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCreated="GridView1_RowCreated">
2 <Columns>
3 <asp:TemplateField HeaderText="序号">
4 <ItemTemplate>
5 <asp:Label ID="Lb_SNum" runat="server" Text='<%#Container.DataItemIndex + 1 %>'></asp:Label>
6 </ItemTemplate>
7 <ItemStyle HorizontalAlign="Center" Width="5%" Wrap="False" />
8 <HeaderStyle HorizontalAlign="Center" Wrap="False" />
9 </asp:TemplateField>
10 <asp:TemplateField HeaderText="区域" >
11 <EditItemTemplate>
12 <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Re_CName") %>'></asp:TextBox>
13 </EditItemTemplate>
14 <ItemTemplate>
15 <asp:Label ID="Label1" runat="server" Text='<%# Bind("Re_CName") %>'></asp:Label>
16 </ItemTemplate>
17 </asp:TemplateField>
18 <asp:TemplateField HeaderText="已被抽中数量">
19 <EditItemTemplate>
20 <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("czqty") %>'></asp:TextBox>
21 </EditItemTemplate>
22 <ItemTemplate>
23 <asp:Label ID="Label2" runat="server" Text='<%# Bind("czqty") %>'></asp:Label>
24 </ItemTemplate>
25 </asp:TemplateField>
26 <asp:TemplateField HeaderText="送检数量">
27 <EditItemTemplate>
28 <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("sjqty") %>'></asp:TextBox>
29 </EditItemTemplate>
30 <ItemTemplate>
31 <asp:Label ID="Label3" runat="server" Text='<%# Bind("sjqty") %>'></asp:Label>
32 </ItemTemplate>
33 </asp:TemplateField>
34 <asp:TemplateField HeaderText="合格">
35 <EditItemTemplate>
36 <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
37 </EditItemTemplate>
38 <ItemTemplate>
39 <asp:Label ID="Label4" runat="server" Text='<%# Bind("yHGqty") %>'></asp:Label>
40 </ItemTemplate>
41 </asp:TemplateField>
42 <asp:TemplateField HeaderText="不合格">
43 <EditItemTemplate>
44 <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
45 </EditItemTemplate>
46 <ItemTemplate>
47 <asp:Label ID="Label5" runat="server" Text='<%# Bind("yBHGqty") %>'></asp:Label>
48 </ItemTemplate>
49 </asp:TemplateField>
50 <asp:TemplateField HeaderText="处理中">
51 <EditItemTemplate>
52 <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
53 </EditItemTemplate>
54 <ItemTemplate>
55 <asp:Label ID="Label6" runat="server" Text='<%# Bind("yCLZqty") %>'></asp:Label>
56 </ItemTemplate>
57 </asp:TemplateField>
58 <asp:TemplateField HeaderText="未送检数量">
59 <EditItemTemplate>
60 <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("wsjqty") %>'></asp:TextBox>
61 </EditItemTemplate>
62 <ItemTemplate>
63 <asp:Label ID="Label3" runat="server" Text='<%# Bind("wsjqty") %>'></asp:Label>
64 </ItemTemplate>
65 </asp:TemplateField>
66 <asp:TemplateField HeaderText="合格">
67 <EditItemTemplate>
68 <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
69 </EditItemTemplate>
70 <ItemTemplate>
71 <asp:Label ID="Label4" runat="server" Text='<%# Bind("HGqty") %>'></asp:Label>
72 </ItemTemplate>
73 </asp:TemplateField>
74 <asp:TemplateField HeaderText="不合格">
75 <EditItemTemplate>
76 <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
77 </EditItemTemplate>
78 <ItemTemplate>
79 <asp:Label ID="Label5" runat="server" Text='<%# Bind("BHGqty") %>'></asp:Label>
80 </ItemTemplate>
81 </asp:TemplateField>
82 <asp:TemplateField HeaderText="处理中">
83 <EditItemTemplate>
84 <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
85 </EditItemTemplate>
86 <ItemTemplate>
87 <asp:Label ID="Label6" runat="server" Text='<%# Bind("CLZqty") %>'></asp:Label>
88 </ItemTemplate>
89 </asp:TemplateField>
90 </Columns>
91 </asp:GridView>
我的淘宝店:http://hamby.taobao.com