自定义gridview编辑并阻止显示更新/取消

时间:2013-07-02 13:49:11

标签: c# asp.net

我的数据库中的一个字段可能有数百甚至数千个字。我想知道如何使gridview中的编辑按钮作为动作事件工作,但也关闭其余的自动功能。我的意思是我不希望表格中的实际单元格可编辑,我不希望更新和取消按钮变得可见。

这是gridview:

   <asp:Panel ID="updatePanel" runat="server" Visible="false">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource4"
            AllowPaging="True" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
            BorderWidth="1px" CellPadding="3" CellSpacing="2" OnRowDeleting="GridView1_OnRowDeleting" OnRowEditing="GridView1_OnRowEditing" 
            DataKeyNames="PK_DailyTaskHours, PK_NonScrumStory">
            <Columns>
                <asp:BoundField DataField="Catagory" HeaderText="Support Catagory" SortExpression="Catagory" />
                <asp:BoundField DataField="AppName" HeaderText="Application Name" SortExpression="IncidentNumber" />
                <asp:BoundField DataField="IncidentNumber" HeaderText="Incident #" SortExpression="IncidentNumber" />
                <asp:BoundField DataField="Hours" HeaderText="Hours" SortExpression="Hours" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:BoundField DataField="CreatedDate" HeaderText="Created Date" SortExpression="CreatedDate" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FFF1D4" />
            <SortedAscendingHeaderStyle BackColor="#B95C30" />
            <SortedDescendingCellStyle BackColor="#F1E5CE" />
            <SortedDescendingHeaderStyle BackColor="#93451F" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
            SelectCommand="SELECT [NonScrumStory].[IncidentNumber], [NonScrumStory].[Description], [NonScrumStory].[CreatedDate], 
            [DailyTaskHours].[Hours], [Application].[AppName], [SupportCatagory].[Catagory], [DailyTaskHours].[PK_DailyTaskHours], 
            [NonScrumStory].[PK_NonScrumStory] FROM [NonScrumStory], [DailyTaskHours], [Application], [SupportCatagory] WHERE 
            ([NonScrumStory].[UserId] = @userIdSelected) AND ([NonScrumStory].[PK_NonScrumStory] = [DailyTaskHours].[NonScrumStoryId]) 
            AND ([NonScrumStory].[CatagoryId] = [SupportCatagory].[PK_SupportCatagory]) AND 
            ([NonScrumStory].[ApplicationId] = [Application].[PK_Application]) AND ([NonScrumStory].[Deleted] != 1)"
            DeleteCommand="UPDATE [NonScrumStory] SET [Deleted] = 1 WHERE (PK_NonScrumStory = @nonScrumStoryPK); 
            UPDATE [DailyTaskHours] SET [Deleted] = 1 WHERE (PK_DailyTaskHours = @dailyTaskHoursPK); ">
            <SelectParameters>
                <asp:QueryStringParameter Name="userIdSelected" Type="String" />
            </SelectParameters>
            <DeleteParameters>
                <asp:QueryStringParameter Name="dailyTaskHoursPK" Type="String" />
                <asp:QueryStringParameter Name="nonScrumStoryPK" Type="String" />
            </DeleteParameters>
        </asp:SqlDataSource>

此外,我有行动事件:

protected virtual void GridView1_OnRowEditing(object sender, GridViewEditEventArgs e)
{

}

我知道使用ReadOnly="false"可以防止细胞变得可编辑。如何摆脱更新/取消?是否可以立即执行取消,以便用户看不到更改? 当用户按下编辑时,显示网格视图的面板将变为不可见,并且将显示带有编辑选项的新面板。

0 个答案:

没有答案