Gridview 复合表头

Posted 会一

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gridview 复合表头相关的知识,希望对你有一定的参考价值。

效果图:技术分享

WEB页:

<asp:GridView CssClass="grid" ID="grv" AutoGenerateColumns="False" runat="server"
            EnableModelValidation="True" OnRowDataBound="grv_RowDataBound" Width="98%"
            onselectedindexchanged="grv_SelectedIndexChanged">
            <RowStyle CssClass="rowStyle" Wrap="False" />
            <AlternatingRowStyle CssClass="alterStyle" Wrap="False" />
            <Columns>
                <asp:BoundField HeaderText="序号" />
                <asp:BoundField DataField="materialId" HeaderText="物料编号" />
                <asp:BoundField DataField="materialName" HeaderText="物料名称" />
                <asp:BoundField DataField="Spec" HeaderText="物料描述" />
                <%-- <asp:TemplateField HeaderText="设计">
                    <ItemTemplate>
                        <asp:TextBox ID="txtDesign" runat="server" Text=‘<%# Bind("Designer") %>‘ Width="60px"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>--%>
                <asp:TemplateField HeaderText="下单数量">
                    <ItemTemplate>
                        <asp:TextBox ID="txtTotalNum" runat="server" Text=‘<%# Bind("TotalCount") %>‘ Width="60px"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="是否有条码">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddlIsBarcode" runat="server" Width="50px">
                            <asp:ListItem Value="0">无</asp:ListItem>
                            <asp:ListItem Value="1">有</asp:ListItem>
                        </asp:DropDownList>
                        <asp:Label ID="lblIsBarcode" runat="server" Text=‘<%# Bind("IsExistsBarcode") %>‘
                            Visible="false"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="状态">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddlIsState" runat="server" Width="60px">
                            <asp:ListItem Value="0">焊接完</asp:ListItem>
                            <asp:ListItem Value="1">喷胶完</asp:ListItem>
                            <asp:ListItem Value="2">老化完</asp:ListItem>
                        </asp:DropDownList>
                        <asp:Label ID="lblIsPj" runat="server" Text=‘<%# Bind("IsPj") %>‘ Visible="false"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="goodnum" HeaderText="合格数量" />
                <asp:BoundField DataField="repairbacknum" HeaderText="不合格数量" />
                <asp:BoundField DataField="confirmor1" HeaderText="检验人" />
                <asp:BoundField DataField="confirmDate1" HeaderText="检验日期" DataFormatString="{0:yyyy-MM-dd}" />
                <asp:TemplateField HeaderText="下步工序">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddlNextStep" runat="server" Width="50px">
                            <asp:ListItem Value="1">喷胶</asp:ListItem>
                            <asp:ListItem Value="2">老化</asp:ListItem>
                            <asp:ListItem Value="3">入库</asp:ListItem>
                        </asp:DropDownList>
                        <asp:Label ID="lblNextStep" runat="server" Text=‘<%# Bind("Nextstep") %>‘ Visible="false"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="备 注">
                    <ItemTemplate>
                        <asp:TextBox ID="txtMemo" runat="server" Text=‘<%# Bind("memo") %>‘ Width="100px"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle CssClass="grid_foot" />
        </asp:GridView>

 

designer页:


        protected void grv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                #region
                string header = "序号#物料编号#物料名称#物料描述#数量#是否有条码#状态#检验结果 合格数量,不合格数量,检验人,检验日期#下步工序#备注";
                GridViewTHeaderHepler help = new GridViewTHeaderHepler();
                e.Row.CssClass = "fixedHeaderTr";
                e.Row.BackColor = System.Drawing.Color.Beige;
                help.SplitTableHeader(e.Row, header);

                //e.Row.Cells[0].Width = 30;
                //e.Row.Cells[1].Width = 110;
                //e.Row.Cells[2].Width = 110;
                //e.Row.Cells[3].Width = 60;
                //e.Row.Cells[4].Width = 30;
                //e.Row.Cells[5].Width = 350;
                //e.Row.Cells[6].Width = 200;
                //e.Row.Cells[7].Width = 90;
                //e.Row.Cells[8].Width = 100;
                #endregion
            } }

以上是关于Gridview 复合表头的主要内容,如果未能解决你的问题,请参考以下文章

很急GridView固定表头和指定列

如何设置winform中gridview的表头宽度,及编号

如何让Gridview在没有数据的时候显示表头

菜鸟提问:如何让GridView的表头内容居中

c#winfrom中gridview控件怎样设置让表头不可点击,还有下面点击全选中,还不是点击只显示一个单元格,求助,谢

gridview的对齐问题