【问题标题】:Gridview colspan of footer button页脚按钮的Gridview colspan
【发布时间】:2013-05-22 09:31:02
【问题描述】:

我有一个网格视图,目前看起来像这样:

我想使用显示添加新行的按钮制作单元格,以跨越其上方按钮的 2 列。

我还想在其他 4 列上添加文本框,并有效地使该行成为“添加用户行”。我是初学者,仍在试验中,详细的解释将非常有帮助。

这是html代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="Admin.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="css/admin.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <header class="grid_9">פאנל מנהל</header>
    <div class="grid_9 block_head">
        טבלת משתמשים
    </div>
    <div class="block grid_9" id="user_block" runat="server">
        <asp:GridView ID="gdview" OnRowEditing="gdview_RowEditing" DataKeyNames="id" AutoGenerateColumns="False"
            CssClass="Grid" OnRowUpdating="gdview_RowUpdating" OnRowCancelingEdit="gdview_RowCancelingEdit"
            runat="server" HeaderStyle-CssClass="tableheader" OnRowDeleting="gdview_RowDeleting" OnRowCreated="RowCreated"
            ShowFooter="true">
            <Columns>
                <asp:BoundField HeaderText="מספר מזהה" DataField="id" ReadOnly></asp:BoundField>
                <asp:BoundField HeaderText="שם משתמש" DataField="username"></asp:BoundField>
                <asp:BoundField HeaderText="סיסמא" DataField="password"></asp:BoundField>
                <asp:BoundField HeaderText="אימייל" DataField="email"></asp:BoundField>

                <asp:CommandField ShowEditButton="True" CancelText="בטל" UpdateText="עדכן" EditText="ערוך"></asp:CommandField>

                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkdel" runat="server" Text="מחק" CommandName="Delete"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <FooterTemplate>
                        <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" />
                    </FooterTemplate>
                </asp:TemplateField>

            </Columns>
        </asp:GridView>
    </div>
</asp:Content>

谢谢!

【问题讨论】:

    标签: c# html asp.net gridview


    【解决方案1】:

    这可能对某人有所帮助。以下链接上的解决方案对我有用: https://www.codeproject.com/Answers/544063/HowplustoplusMergepluscellsplusinplusAsp-netplusGr#answer1

    来自链接的片段:

    gvitems.FooterRow.Cells[0].ColumnSpan = 7;
    gvitems.FooterRow.Cells.RemoveAt(1);
    gvitems.FooterRow.Cells.RemoveAt(2);
    gvitems.FooterRow.Cells.RemoveAt(3);
    gvitems.FooterRow.Cells.RemoveAt(4);
    gvitems.FooterRow.Cells.RemoveAt(5);
    gvitems.FooterRow.Cells.RemoveAt(6);
    

    【讨论】:

    • 这很好,但有问题。当您删除索引为 1 的单元格时,之后的所有其他单元格会将其索引更改为之前的索引 - 1。因此,当您删除索引为 2 的单元格时,您实际上是在跳过曾经是索引为 2 的单元格,现在是索引 1,而不是删除曾经是索引 3 的单元格,现在是 2。在某些时候,您将用完单元格并且您将遇到索引违规(如果您只有 7 个单元格)。正确的做法是颠倒删除单元格的顺序,从索引为 6 的单元格开始,然后是 5、4、3、2 和 1。
    • Joe Salazar,真的帮了我这个忙,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 2015-09-28
    相关资源
    最近更新 更多