Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

I have created a databound grid view in a web application and trying to edit the rows throught each row's edit button. But on pressing the edit button the row is still fix and edit is not allowed. Though the Update and cancel button appears.

following is code in vb
VB
Protected Sub DataGridView1_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles DataGridView1.RowEditing
        DataGridView1.EditIndex = e.NewEditIndex
        Call fnShowBom()***(function to call data from sql and bind the grid)

    End Sub


Thanks in advance

gridview code:
XML
<asp:GridView ID="DataGridView1"
       runat="server"
       AutoGenerateColumns="false"
       DataKeyNames="BOMIC"
       showfooter="true"
       enablesorting="true"
       CssClass="Grid"
       AllowSorting="True"
       BorderStyle="Groove"
       onrowcancellingedit="datagridview1_rowcancellingedit"
       onrowdatabound="DataGridView1_RowDataBound"
       onrowediting="DataGridView1_RowEditing"
       onrowupdating="DataGridView1_RowUpdating"
       onrowcommand="DataGridview1_Rowcommand"
       onrowdeleting="DataGridView1_RowDeleting"
       onselectedindexchanged="DataGridView1_SelectedIndexChanged"
       >
      <HeaderStyle CssClass="GridHeader" />
       <RowStyle CssClass="GridItem" />
       <AlternatingRowStyle CssClass="GridAltItem" />

       <Columns>
           <asp:TemplateField HeaderText="Item Code"  HeaderStyle-HorizontalAlign="Left">
               <EditItemTemplate>
                   <asp:Label ID="BOMIC" runat="server" Text='<%# Bind("BOMIC")%>'></asp:Label>
               </EditItemTemplate>
               <ItemTemplate>
                   <asp:Label ID="BOMIC" runat="server" Text='<%# Bind("BOMIC") %>'></asp:Label>
               </ItemTemplate>
           </asp:TemplateField>

            <asp:TemplateField HeaderText="Description"  HeaderStyle-HorizontalAlign="Center">
               <EditItemTemplate>
                   <asp:Label ID="BOMIN" runat="server" Text='<%# Bind("BOMIN")%>'></asp:Label>
               </EditItemTemplate>
               <ItemTemplate>
                   <asp:Label ID="BOMIN" runat="server" Text='<%# Bind("BOMIN") %>'></asp:Label>
               </ItemTemplate>
           </asp:TemplateField>

           <asp:TemplateField HeaderText="Qty"  HeaderStyle-HorizontalAlign="Center">
               <EditItemTemplate>
                   <asp:Label ID="BOMIQ" runat="server" Text='<%# Bind("BOMIQ")%>'></asp:Label>
               </EditItemTemplate>
               <ItemTemplate>
                   <asp:Label ID="BOMIQ" runat="server" Text='<%# Bind("BOMIQ")%>'></asp:Label>
               </ItemTemplate>
           </asp:TemplateField>

           <asp:TemplateField HeaderText="Vendor"  HeaderStyle-HorizontalAlign="Center">
               <EditItemTemplate>
                   <asp:Label ID="BOMIV" runat="server" Text='<%# Bind("BOMIV")%>'></asp:Label>
               </EditItemTemplate>
               <ItemTemplate>
                   <asp:Label ID="BOMIV" runat="server" Text='<%# Bind("BOMIV")%>'></asp:Label>
               </ItemTemplate>
           </asp:TemplateField>


           <asp:TemplateField HeaderText="Page No."  HeaderStyle-HorizontalAlign="Center">
               <EditItemTemplate>
                   <asp:Label ID="BOMIRM" runat="server" Text='<%# Bind("BOMIRM")%>'></asp:Label>
               </EditItemTemplate>
               <ItemTemplate>
                   <asp:Label ID="BOMIRM" runat="server" Text='<%# Bind("BOMIRM")%>'></asp:Label>
               </ItemTemplate>
           </asp:TemplateField>

           <asp:TemplateField HeaderText="Edit" ShowHeader="False" HeaderStyle-HorizontalAlign="Left">
               <EditItemTemplate>
                   <asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
                   <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
               </EditItemTemplate>
               <FooterTemplate>
                   <asp:LinkButton ID="lnkAdd" runat="server" CausesValidation="False" CommandName="Insert" Text="Insert"></asp:LinkButton>
               </FooterTemplate>
               <ItemTemplate>
                   <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
               </ItemTemplate>
           </asp:TemplateField>

           <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" />


      </Columns>

   </asp:GridView>
Posted
Updated 22-May-14 22:48pm
v2
Comments
Animesh Datta 23-May-14 4:38am    
put your gridview design here.

1 solution

Hello ,
to get Gridview in Edit mode you have to use TemplateField .and you must use asp:TextBox in the EditItemTemplate instead of asp:Label . For more details
Refer: Simple Insert-Select-Edit-Update in Asp.net Gridview
thanks
 
Share this answer
 
v2
Comments
atul sharma 5126 23-May-14 5:09am    
It worked. Thanks a lot
Animesh Datta 23-May-14 5:10am    
you are welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900