Click here to Skip to main content
15,916,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The code in aspx and aspx.cs was given But the grid view was not editable
when i click the edit button on grid the textboxs are not displaying.

Can you please help me............Please

This is my code in aspx.cs page:
C#
protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
       {
           Label lblid = gv.Rows[e.RowIndex].FindControl("lblid") as Label;
           TextBox lstname = gv.Rows[e.RowIndex].FindControl("lstname")as TextBox;
           TextBox fstname= gv.Rows[e.RowIndex].FindControl("fstname")as TextBox;
           TextBox titlee = gv.Rows[e.RowIndex].FindControl("titlee")as TextBox;
           TextBox adress = gv.Rows[e.RowIndex].FindControl("adress")as TextBox;
           TextBox City   = gv.Rows[e.RowIndex].FindControl("City")as TextBox;
           TextBox region = gv.Rows[e.RowIndex].FindControl("region")as TextBox;
           TextBox Pcode  = gv.Rows[e.RowIndex].FindControl("Pcode")as TextBox;
           TextBox country = gv.Rows[e.RowIndex].FindControl("country")as TextBox;
           TextBox extenction= gv.Rows[e.RowIndex].FindControl("extenction")as TextBox;

           if (lblid != null && lstname != null && fstname != null && titlee != null && adress != null && City != null && region != null && Pcode != null && country != null && extenction != null)
           {
               Employee emp = new Employee();
               emp.empid = Convert.ToInt32(lblid.Text.Trim());
               emp.Lastname = lstname.Text;
               emp.Firstname = fstname.Text;
               emp.Title = titlee.Text;
               emp.Address = adress.Text;
               emp.City = City.Text;
               emp.Region = region.Text;
               emp.Postalcode = Pcode.Text;
               emp.Country = country.Text;
               emp.Extenction = extenction.Text;

               if (evnt.updateemp(emp) == true)
               {
                   lblerror.Text = "Updated Sucessfully";
               }
               else
               {
                   lblerror.Text = "failed";
               }
               gv.EditIndex = -1;
               binddata();
           }


       }

This is my code in aspx page:
C#
<asp:GridView ID="gv" runat="server" AutoGenerateEditButton="True" AutoGenerateColumns="False"
           OnRowCancelingEdit="gv_RowCancelingEdit" OnRowDeleting="gv_RowDeleting"
           OnRowUpdating="gv_RowUpdating" CellPadding="4" ForeColor="#333333"
           GridLines="None" OnRowEditing="gv_RowEditing">
                   <AlternatingRowStyle BackColor="White" />
                   <EditRowStyle BackColor="#2461BF" />
                   <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                   <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                   <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                   <RowStyle BackColor="#EFF3FB" />
                   <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                   <SortedAscendingCellStyle BackColor="#F5F7FB" />
                   <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                   <SortedDescendingCellStyle BackColor="#E9EBEF" />
                   <SortedDescendingHeaderStyle BackColor="#4870BE" />
                   <Columns>

                   <asp:TemplateField HeaderText="EmployeeID">
                   <EditItemTemplate>
                   <asp:Label ID="lblid" runat="server" Text='<%#Eval("empid") %>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable1" runat="server" Text='<%#Eval("empid") %>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   <asp:TemplateField HeaderText="LastName">
                   <EditItemTemplate>
                   <asp:Label ID="lstname" runat="server" Text='<%#Eval("lastname") %>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable2" runat="server" Text='<%#Eval("lastname") %>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   <asp:TemplateField HeaderText="Firstname">
                   <EditItemTemplate>
                   <asp:Label ID="fstname" runat="server" Text='<%#Eval("firstname") %>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable3" runat="server" Text='<%#Eval("firstname")%>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   <asp:TemplateField HeaderText="Title">
                   <EditItemTemplate>
                   <asp:Label ID="titlee" runat="server" Text='<%#Eval("title") %>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable4" runat="server" Text='<%#Eval("title") %>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   <asp:TemplateField HeaderText="Address">
                   <EditItemTemplate>
                   <asp:Label ID="adress" runat="server" Text='<%#Eval("address") %>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable5" runat="server" Text='<%#Eval("address") %>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   <asp:TemplateField HeaderText="City">
                   <EditItemTemplate>
                   <asp:Label ID="City" runat="server" Text='<%#Eval("city")%>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable6" runat="server" Text='<%#Eval("city")%>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   <asp:TemplateField HeaderText="region">
                   <EditItemTemplate>
                   <asp:Label ID="region" runat="server" Text='<%#Eval("region") %>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable7" runat="server" Text='<%#Eval("region") %>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   <asp:TemplateField HeaderText="Postalcode">
                   <EditItemTemplate>
                   <asp:Label ID="Pcode" runat="server" Text='<%#Eval("postalcode")%>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable8" runat="server" Text='<%#Eval("postalcode")%>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   <asp:TemplateField HeaderText="Country">
                   <EditItemTemplate>
                   <asp:Label ID="country" runat="server" Text='<%#Eval("country") %>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable9" runat="server" Text='<%#Eval("country") %>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   <asp:TemplateField HeaderText="Extension">
                   <EditItemTemplate>
                   <asp:Label ID="extenction" runat="server" Text='<%#Eval("extenction") %>'></asp:Label>
                   </EditItemTemplate>
                   <ItemTemplate>
                   <asp:Label ID="lable10" runat="server" Text='<%#Eval("extenction") %>'></asp:Label>
                   </ItemTemplate>
                   </asp:TemplateField>

                   </Columns>
                   </asp:GridView>
Posted
Updated 23-Aug-13 1:27am
v3
Comments
[no name] 23-Aug-13 7:49am    
Labels != Textboxes

1 solution

I didn't find a single textbox in your code. It should be something like
C#
<edititemtemplate>
     <asp:label id="extenction" runat="server" text="<%#Eval("extenction") %"> </asp:label>//It should be textbox,not label
</edititemtemplate>

Regards..:)
 
Share this answer
 
v2
Comments
Thanks7872 23-Aug-13 8:15am    
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