You must Sign In to post a response.
  • Category: ASP.NET

    Who avoid this gridview Error.

    Hi,
    I am using datagrid And have lost experience in datagrid. Now our Team leader has
    told me use Gridview instead of datagrid. I am first trying to edit row of
    gridview. I want display rows values in my Textbox and then will try to update or
    delete as my requirement. But still i am getting below error.

    'The GridView 'gvPersonalInformation' fired event RowEditing which wasn't handled.'


    <div style="width: 80%">
    <table width="100%" border="1" cellpadding="2" cellspacing="2">
    <tr>
    <td colspan="2" align="center" style="font-size: 20px; font-weight: bold;">
    Personal informations
    </td>
    </tr>
    <tr>
    <td style="width: 25%;">
    First Name :
    </td>
    <td>
    <asp:TextBox ID="tbFirstName" runat="server" Width="200px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>
    Middle Name :
    </td>
    <td>
    <asp:TextBox ID="tbMiddleName" runat="server" Width="200px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>
    Last Name :
    </td>
    <td>
    <asp:TextBox ID="tbLastName" runat="server" Width="200px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <asp:Button ID="bAdd" runat="server" Text="Add Details" Width="100px" Height="35px"
    OnClick="bAdd_Click" />
    </td>
    </tr>
    </table>
    <br />
    <table width="80%" cellpadding="2" cellspacing="2">
    <tr>
    <asp:GridView ID="gvPersonalInformation" runat="server" AutoGenerateColumns="False"
    Width="100%" CellPadding="4" ForeColor="#333333" GridLines="None">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>
    <asp:TemplateField HeaderText="ID">
    <ItemTemplate>
    <asp:Label ID="lblID" runat="server" Text='<%#Eval("ID") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="First Name">
    <ItemTemplate>
    <asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FIRSTNAME") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Middle Name">
    <ItemTemplate>
    <asp:Label ID="lblMiddleName" runat="server" Text='<%#Eval("MIDDLENAME") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Last Name">
    <ItemTemplate>
    <asp:Label ID="lblLastName" runat="server" Text='<%#Eval("LASTNAME") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Edit">
    <ItemTemplate>
    <asp:Button ID="bEdit" runat="server" Text="Edit" CommandName="Edit" Width="75px"
    Height="25px" OnClick="bEdit_Click" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Delete">
    <ItemTemplate>
    <asp:Button ID="bDelete" runat="server" Text="Delete" Width="75px" Height="25px"
    OnClientClick="javascript: return confirm('Are you sure want to Delete the Customer?');"
    OnClick="bDelete_Click" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </tr>
    </table>
    <br />
    <table width="100%" cellpadding="2" cellspacing="2">
    <tr>
    <td colspan="2" align="center">
    <asp:Button ID="bSaveData" runat="server" Text="Save To Database" Width="150px" Height="35px"
    OnClick="bSaveData_Click" />
    </td>
    </tr>
    </table>
    </div>


    protected void bEdit_Click(object sender, EventArgs e)
    {
    try
    {
    Button bnEdit = sender as Button;

    GridViewRow rows = bnEdit.NamingContainer as GridViewRow;

    string ID = ((Label)rows.FindControl("lblID")).Text;
    this.tbFirstName.Text = ((Label)rows.FindControl("lblFirstName")).Text;
    this.tbMiddleName.Text = ((Label)rows.FindControl("lblMiddleName")).Text;
    this.tbLastName.Text = ((Label)rows.FindControl("lblLastName")).Text;
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }
  • #768974
    Hi,

    Have you try to change the command property?

    Just change the "CommandName" property of the "Edit" button from "Edit" to "EditRow"(or something else which is relevent to you but make sure it is not "Edit").

    Hope now it will work.

    Thanks,
    Mani

  • #768979
    Hai Chandrasekhar,
    As per the error message "'The GridView 'gvPersonalInformation' fired event RowEditing which wasn't handled.'", you need to implement this event for the GridView.
    For the reference, you can use the below code snippet code:

    https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting(v=vs.110).aspx

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768999
    Hi,

    In gridview we have several events to perform actions, for example in your case you need to edit the gridview row and update the items or delete the items in that case you have to maintain several events

    for editing you have to be use gridview RowEditing event using this you can able to edit the gridview row,

    for example if you want to update the edited record then you have to use gridviewRowUpdate event,

    for example if you want to delete the row then you have to use gridviewRowDelete event..

    but as I seen you haven't used any events while design your gridview control.

    First implement those event by referring below link,
    http://www.dotnetspider.com/resources/44926-GridView-Edit-Cancel-Update-Delete-ASPnet.aspx

    If you still got problem then please let us know...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments