5

我正在使用 ASP.NET C# 网格视图,我想在控制中编辑显示在同一页面上的数据。但是当我编写网格视图行编辑事件时,它会在网格视图行中显示文本框,谁能帮助我如何使用 rowediting 事件禁用网格视图中的内联编辑?

<asp:GridView ID="gvItems" runat="server" AutoGenerateColumns="False" AllowPaging="True"
            BorderStyle="Solid" BorderWidth="1px" CellPadding="4" ForeColor="#333333" GridLines="None"
            OnPageIndexChanging="gvItems_PageIndexChanging" Width="901px"
            OnRowCommand="gvItems_RowCommand" OnSelectedIndexChanged="gvItems_SelectedIndexChanged" OnRowDataBound="gvItems_RowDataBound" OnRowEditing="gvItems_RowEditing">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:ButtonField  Text="Edit" CommandName="Change" />
                <asp:ButtonField  Text="Addend" CommandName="Addend"  />
                <asp:BoundField DataField="ItemID" HeaderText="ID" />
                <asp:BoundField DataField="Project" HeaderText="Project" SortExpression="Project" />
                <asp:BoundField DataField="Type" HeaderText="Type" />
                <asp:BoundField DataField="Release" HeaderText="Release" />
                <asp:BoundField DataField="Priority" HeaderText="Priority" />
                <asp:BoundField DataField="Severity" HeaderText="Severity" />
                <asp:BoundField DataField="Client" HeaderText="Client" />
                <asp:BoundField DataField="Status" HeaderText="Status" />
                <asp:BoundField DataField="Subject" HeaderText="Subject" />
                <asp:BoundField DataField="CreatedDate" DataFormatString="{0:d}" HeaderText="Created Date" />

                <asp:TemplateField>
                    <ItemTemplate>
                        <!--To fire the OnRowEditing event.-->
                        <asp:LinkButton ID="lbView" runat="server" CommandName="View"
                            Text="View" CommandArgument="<%# Container.DataItemIndex %>">
                        </asp:LinkButton>
                      <asp:HiddenField runat="server" ID="hdnItemID" Value='<%#Eval("ItemID") %>'>
                                    </asp:HiddenField>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>

            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
            <PagerSettings Mode="NumericFirstLast" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <SortedAscendingCellStyle BackColor="#FDF5AC" />
            <SortedAscendingHeaderStyle BackColor="#4D0000" />
            <SortedDescendingCellStyle BackColor="#FCF6C0" />
            <SortedDescendingHeaderStyle BackColor="#820000" />
        </asp:GridView>
4

3 回答 3

5

我遇到了同样的问题,经过一番挣扎,我发现问题出CommandName在我的情况下。

我将Edit更改为edt并将Delete更改为del,从那时起该gridViewName_RowEditing事件就再也没有触发过。

于 2013-09-02T07:11:05.450 回答
3

<EditItemTemplate></EditItemTemplate>从网格视图中删除<asp:TemplateField></asp:TemplateField>

于 2012-12-22T09:06:04.130 回答
0

你会尝试使用下面的链接

http://csharpdotnetfreak.blogspot.no/2008/12/hide-gridview-columns-in-normal-mode.html?m=1

于 2012-12-22T09:05:10.477 回答