简体   繁体   English

搜索特定行时未处理的GridView触发事件RowEditing

[英]The GridView fired event RowEditing which wasn't handled when search for specific row

I have a grid view with 2 columns one for textbox and the other for edit icon. 我有一个带有2列的网格视图,一列用于文本框,另一列用于编辑图标。 If I click on edit icon, it opened the textbox for editing and the second column will contain update icon and cancel icon. 如果单击编辑图标,它将打开文本框进行编辑,第二列将包含更新图标和取消图标。 Also there is a search textbox above the gridview to allow the user search for specefic row. 在gridview上方还有一个搜索文本框,允许用户搜索特定的行。

First scenario: when i have for example 5 rows and click on edit icon in any row, it will open the edit box and i can edit. 第一种情况:例如,当我有5行并单击任意行中的编辑图标时,它将打开编辑框,我可以进行编辑。

Second scenario: when i type text in search field and click on search button it will retrieve the corresponding row and display it in the grid view alone. 第二种情况:当我在搜索字段中键入文本并单击搜索按钮时,它将检索相应的行并将其单独显示在网格视图中。

The problem is When I click on edit icon for this row (search result), it shows: The GridView fired event RowEditing which wasn't handled 问题是,当我单击该行(搜索结果)的编辑图标时,它显示:GridView引发了未处理的事件RowEditing

This is my gridview: 这是我的gridview:

<asp:GridView ID="PSGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="StatusID" DataSourceID="PSSqlDataSource" ShowFooter="True" BorderStyle="None" BorderWidth="1px" Width="100%" ShowHeaderWhenEmpty="True" EmptyDataText="No protocal status."
  AllowPaging="true" PageSize="10" CssClass="table table-bordered table-striped table-condensed mb-none" AllowSorting="True" OnRowCommand="PSGridView_RowCommand">
  <Columns>
    <%--RP col--%>
      <asp:TemplateField HeaderText="Protocol Status" HeaderStyle-CssClass="caption font-green" HeaderStyle-Width="90%">
        <EditItemTemplate>
          <asp:TextBox ID="PSBind" runat="server" Text='<%# Bind("Des") %>' Width="100%" CssClass="form-control"></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="PSLabel" runat="server" Text='<%# Bind("Des") %>' Width="100%"></asp:Label>
        </ItemTemplate>
        <FooterTemplate>
          <asp:TextBox ID="PS" runat="server" Width="100%" CssClass="form-control"></asp:TextBox>
        </FooterTemplate>
      </asp:TemplateField>
      <%--Action col--%>

        <asp:TemplateField HeaderText="Actions" HeaderStyle-CssClass="caption font-green" HeaderStyle-Width="10%">
          <ItemTemplate>
            <asp:LinkButton ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" ToolTip="Edit">
              <i class="fa fa-lg fa-pencil"></i></asp:LinkButton>&nbsp;&nbsp;&nbsp;
            <%--<asp:LinkButton ID="btnDelete" runat="server"  CausesValidation="false"  CommandArgument="<%# Container.DataItemIndex %>" CommandName="DeletePS" OnClientClick="return FinalDeleteConfirm(this, event);" Text="Delete" ToolTip="Delete">--%>
              <asp:LinkButton ID="btnDelete" runat="server" CausesValidation="false" CommandArgument="<%# Container.DataItemIndex %>" CommandName="DeletePS" OnClientClick="DeleteConfirm()" Text="Delete" ToolTip="Delete">
                <i class="fa fa-lg fa-trash-o" style="color:red;"></i></asp:LinkButton>
          </ItemTemplate>

          <EditItemTemplate>
            <asp:LinkButton ID="btnUpdate" runat="server" CommandName="UpdatePS" CommandArgument="<%# Container.DataItemIndex %>" Text="Update" ToolTip="Confirm">
              <i class="fa fa-lg fa-check" style="color:green"></i></asp:LinkButton>&nbsp;&nbsp;&nbsp;
            <asp:LinkButton ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel" ToolTip="Cancel">
              <i class="fa fa-lg fa-times" style="color:red"></i></asp:LinkButton>
          </EditItemTemplate>

          <FooterTemplate>
            <button id="btnAdd" class="btn btn-primary btn-circle" type="button" runat="server" onserverclick="btnAdd_Click">
            <i class="fa fa-plus"></i>
            &nbsp;Add Protocol Status   
            </button>
          </FooterTemplate>
        </asp:TemplateField>
  </Columns>

  <PagerStyle CssClass="pagination-marwa" />
  <SortedAscendingCellStyle BackColor="#FFFDE7" />
  <SortedAscendingHeaderStyle BackColor="#FFF9C4" />
  <SortedDescendingCellStyle BackColor="#FFFDE7" />
  <SortedDescendingHeaderStyle BackColor="#FFF9C4" />
</asp:GridView>

<asp:SqlDataSource ID="PSSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ProtocolConnectionString %>" SelectCommand="ProtocolStatus_Select" DeleteCommand="ProtocolStatus_Delete" InsertCommand="ProtocolStatus_Insert" UpdateCommand="ProtocolStatus_Update"
  DeleteCommandType="StoredProcedure" InsertCommandType="StoredProcedure" SelectCommandType="StoredProcedure" UpdateCommandType="StoredProcedure">

  <DeleteParameters>
    <asp:Parameter Name="StatusID" Type="Int32" />
  </DeleteParameters>

  <InsertParameters>
    <asp:Parameter Name="Des" Type="String" />
  </InsertParameters>

  <UpdateParameters>
    <asp:Parameter Name="StatusID" Type="Int32" />
    <asp:Parameter Name="Des" Type="String" />
  </UpdateParameters>

</asp:SqlDataSource>

code behind c#: C#背后的代码:

protected void PSGridView_RowCommand(object sender, GridViewCommandEventArgs e) {
        var exist = 0;            
        if (e.CommandName == "DeletePS" )
        {
            some code
        }

        else if (e.CommandName == "UpdatePS")
        {
            var exist1 = 0;    
            //When update, check if the new name is already exist in the database
            //*******************************************************************
            var index = Convert.ToInt32(e.CommandArgument);

            if (index >= 10)
            {
                index = index % 10;
            }

            var pageSize = PSGridView.PageSize;
            GridViewRow row = PSGridView.Rows[index % pageSize];
            TextBox txt = row.FindControl("PSBind") as TextBox;
            string t = txt.Text;
            exist1 = check_exist(t);

            if (exist1 == 1)
            {
              errorboxactions.Attributes.Add("style", "display:block");
              errormsgactions.InnerHtml = "This name already exist ! type another name";
            }
            //if not exist
            //*************
            else
            {
               PSGridView.UpdateRow(index, true);
               PSGridView.DataBind();

               updateboxactions.Attributes.Add("style", "display:block");
               updatemsgactions.InnerHtml = "Protocol Status has been updated successfully";
            }                
        } 
    }

just do one simple thing fire RowEditing event for gridview.... Follow steps 只需做一件简单的事情就可以激发gridview的RowEditing事件。

select gridview
go to properties
select events and then double click on row editing and then run the page again.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理的 GridView 触发事件 RowEditing - The GridView fired event RowEditing which wasn't handled GridView 触发了未处理的事件 PageIndexChanging - The GridView fired event PageIndexChanging which wasn't handled GridView的“网格”触发了未处理的事件PageIndexChanging - The GridView 'grid' fired event PageIndexChanging which wasn't handled GridView的'OrdersGridView'触发了未处理的事件RowDeleting - The GridView 'OrdersGridView' fired event RowDeleting which wasn't handled 搜索后排序-gridview1触发了未处理的事件排序 - Sorting after search - gridview1 fired event Sorting which wasn't handled GridView&#39;GridView1&#39;触发了未处理的事件RowDeleting,但是有一个事件 - The GridView 'GridView1' fired event RowDeleting which wasn't handled , but there is an event 错误GridView'GridView1'触发了未处理的事件排序 - error The GridView 'GridView1' fired event Sorting which wasn't handled GridView&#39;&#39;触发了未处理的事件RowUpdating。 ASP.NET背后的C#代码 - The GridView ' ' fired event RowUpdating which wasn't handled. C# code behind asp.net FormView触发了未处理的事件ModeChanging。 - The FormView fired event ModeChanging which wasn't handled. 在GridView中单击“更新”按钮时,将触发RowEditing - RowEditing is fired when update button is clicked in GridView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM