多列标题ASP.NET的GridView [英] Multi column header in ASP.NET GridView

查看:237
本文介绍了多列标题ASP.NET的GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView包含30列,其中几列,我必须设置它就是我有叶名称,叶code,叶子值,叶厂商code顶级单柱,在这里我需要给它的顶部单列为叶标识,叶带状,叶矫直机列叶详情。我没下$ C在没有成功的RowDataBound $ C,新单立柱上all.Could顶部到来请你告诉我,我所做的wrong.One更重要的事情我所做的是,我设置GridView控件属性 PagerSettings顶部位置,这样可以来对电网的顶部,指数值1,2,3等。

这是我的GridView

 < ASP:GridView控件ID =grdcell=服务器的AutoGenerateColumns =FALSEAllowPaging =真每页=13的DataKeyNames =名字,位置
                CELLPADDING =4前景色=#333333OnPageIndexChanging =grdNewcells_PageIndexChangingOnRowDataBound =grdcell_RowDataBound>
                < AlternatingRowStyle背景色=白前景色=#284775/>
                <柱体和GT;
                    < ASP:的TemplateField的HeaderText =插入HeaderStyle-Horizo​​ntalAlign =左>
                        <&HeaderTemplate中GT;
                            < ASP:复选框ID =insertall文本=全部插入的onclick =checkAll(本); =服务器/>
                        < / HeaderTemplate中>
                        <&ItemTemplate中GT;
                            < ASP:复选框ID =insertChk=服务器/>
                        < / ItemTemplate中>
                        < HeaderStyle Horizo​​ntalAlign =左>< / HeaderStyle>
                    < / ASP:的TemplateField>
                    < ASP:BoundField的数据字段=Leaf_NAME的HeaderText =叶名SORTEX pression =Leaf_NAME>< / ASP:BoundField的>
                    < ASP:BoundField的数据字段=Leaf_ code的HeaderText =叶codeSORTEX pression =Leaf_ code>< / ASP:BoundField的>
                    < ASP:BoundField的数据字段=Leaf_Value的HeaderText =叶值SORTEX pression =Leaf_Value>< / ASP:BoundField的>
                    < ASP:BoundField的数据字段=LeafVENDOR_ code的HeaderText =叶厂商codeSORTEX pression =LeafVENDOR_ code>< / ASP:BoundField的>
                    < ASP:BoundField的数据字段=Leaf_ID的HeaderText =叶IDSORTEX pression =Leaf_ID>< / ASP:BoundField的>
                    < ASP:BoundField的数据字段=Leaf_ZOnal的HeaderText =叶纬向SORTEX pression =Leaf_ZOnal>< / ASP:BoundField的>
                    < ASP:BoundField的数据字段=Leaf_Leveller的HeaderText =叶调衡SORTEX pression =Leaf_Leveller>< / ASP:BoundField的>
                    < ASP:BoundField的数据字段=Loaction的HeaderText =LoactionSORTEX pression =Loaction>< / ASP:BoundField的>

和code我在做行数据绑定如下图所示。

  GridViewRow gvRow = e.Row;
                如果(gvRow.RowType == DataControlRowType.Header)
                {
                    如果(gvRow.Cells [1]。文本==Leaf_NAME)
                    {
                        gvRow.Cells.Remove(gvRow.Cells [1]);
                        GridViewRow gvHeader =新GridViewRow(0,0,DataControlRowType.DataRow,DataControlRowState.Insert);
                        TableCell的headerCell0 =新的TableCell()
                        {
                            文本=叶细节
                            Horizo​​ntalAlign = Horizo​​ntalAlign.Center,
                            ROWSPAN = 6
                        };                        gvHeader.Cells.Add(headerCell0);                        grdcell.Controls [0] .Controls.AddAt(0,gvHeader);
                    }
                }


解决方案

我做到了通过下面的链接,但我用的GridView行创建活动

<一个href=\"http://www.aspsnippets.com/Articles/ASPNet-GridView-Group-Header-Row-Columns-and-display-Multiple-Columns-under-Single-Column.aspx\"相对=nofollow>单了多列列

I have a gridview contains 30 columns where few columns i have to set single column on top of it ie i have Leaf Name,Leaf Code,Leaf Value,Leaf Vendor Code,Leaf Id,Leaf ZOnal,Leaf Leveller columns where i need to give single column on top of it as Leaves Details.I did following code in rowdatabound with no success, new single column is coming on top of all.Could you please tell me what i did wrong.One more important thing i did is , i set gridview property PagerSettings Position top so that could come on top of grid as index values 1,2,3 etc.

here is my gridview

 <asp:GridView ID="grdcell" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageSize="13" DataKeyNames="firstname,location"
                CellPadding="4" ForeColor="#333333" OnPageIndexChanging="grdNewcells_PageIndexChanging" OnRowDataBound="grdcell_RowDataBound" >
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:TemplateField HeaderText="Insert" HeaderStyle-HorizontalAlign="Left">
                        <HeaderTemplate>
                            <asp:CheckBox ID="insertall" Text="Insert All" onclick="checkAll(this);" runat="server" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="insertChk" runat="server" />
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Leaf_NAME" HeaderText="Leaf Name" SortExpression="Leaf_NAME"></asp:BoundField>
                    <asp:BoundField DataField="Leaf_CODE" HeaderText="Leaf Code" SortExpression="Leaf_CODE"></asp:BoundField>
                    <asp:BoundField DataField="Leaf_Value" HeaderText="Leaf Value" SortExpression="Leaf_Value"></asp:BoundField>
                    <asp:BoundField DataField="LeafVENDOR_CODE" HeaderText="Leaf Vendor Code" SortExpression="LeafVENDOR_CODE"></asp:BoundField>
                    <asp:BoundField DataField="Leaf_ID" HeaderText="Leaf Id" SortExpression="Leaf_ID"></asp:BoundField>
                    <asp:BoundField DataField="Leaf_ZOnal" HeaderText="Leaf ZOnal" SortExpression="Leaf_ZOnal"></asp:BoundField>
                    <asp:BoundField DataField="Leaf_Leveller" HeaderText="Leaf Leveller" SortExpression="Leaf_Leveller"></asp:BoundField>
                    <asp:BoundField DataField="Loaction" HeaderText="Loaction" SortExpression="Loaction"></asp:BoundField>

and the code what i did in row data bound as shown below

GridViewRow gvRow = e.Row;
                if (gvRow.RowType == DataControlRowType.Header)
                {
                    if (gvRow.Cells[1].Text == "Leaf_NAME")
                    {
                        gvRow.Cells.Remove(gvRow.Cells[1]);
                        GridViewRow gvHeader = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Insert);
                        TableCell headerCell0 = new TableCell()
                        {
                            Text = "Leaves Details",
                            HorizontalAlign = HorizontalAlign.Center,
                            RowSpan = 6
                        };

                        gvHeader.Cells.Add(headerCell0);

                        grdcell.Controls[0].Controls.AddAt(0, gvHeader);
                    }
                }

解决方案

i did it by using following link, but i used gridview row created event

single column for multiple column

这篇关于多列标题ASP.NET的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆