gridview_Row命令中的代码未更新控件状态(例如,文本框文本)

时间:2015-07-25 06:43:41

标签: c# asp.net gridview rowcommand

我使用的是一个简单的gridview,如下所示:

        <asp:GridView ID="grdViewData" runat="server" Width="98%" DataKeyNames="RecordID"                                OnSelectedIndexChanged="grdViewData_SelectedIndexChanged" 
                onrowcommand="grdViewData_RowCommand">
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <Columns>
                <asp:TemplateField ShowHeader="False">
                 <ItemTemplate>
                <asp:LinkButton ID="lnkEdit" runat="server" 
    CausesValidation="False" CommandName="Select" OnClientClick="window.scroll(0,0)" 
    Text="Edit"></asp:LinkButton>
                </ItemTemplate>
                   </asp:TemplateField>
                   <asp:TemplateField ShowHeader="False">
                       <ItemTemplate>
                        <asp:LinkButton ID="lnkDelete" runat="server"
 CausesValidation="False" CommandName="Delete"
OnClientClick="return confirm('Do you want to delete this record?');" Text="Delete"                                                      CommandArgument="<%# Container.DataItemIndex %>"></asp:LinkButton>
            </ItemTemplate>
                   </asp:TemplateField>
         </Columns> </asp:GridView>

为了更新gridview中的记录,我使用gridview_SelectedIndexChanged方法,其中至于删除记录,我使用gridview_RowCommand(如果e.CommandName ==&#34;删除&#34;)方法如下:

     protected void grdViewData_SelectedIndexChanged(object sender, EventArgs e)
    {

    // Code Working properly Controls on page also getting updated

    }

protected void grdViewData_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "Delete")
        {
            // Code to Delete Record (Working Properly, Record being deleted.)

    // Here Onwards code not working
     Message.Text = "Data Deleted Successfully..";
                ErrorMessage.Text = "";

        }

    }

如果更新记录,更新后我有一些代码来更新页面上正常工作的控件,但是如果删除记录,则会删除记录,但页面上的控件不会更新。附加调试器显示代码执行完美,但控件未更新。

我一直在谷歌搜索一天,真的需要知道原因而不是替代。

0 个答案:

没有答案