单击网格视图编辑按钮时不显示文本框
问题描述:
给出了aspx和aspx.cs中的代码但网格视图不可编辑
当我点击网格上的编辑按钮时文本框没有显示。
能帮帮我............请
这是我在aspx.cs页面中的代码:
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:
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();
}
}
这是我的aspx页面中的代码:
This is my code in aspx page:
<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>
答
我的代码中没有找到单个文本框。它应该类似于
I didn't find a single textbox in your code. It should be something like
<edititemtemplate>
<asp:label id="extenction" runat="server" text="<%#Eval("extenction") %"> </asp:label>//It should be textbox,not label
</edititemtemplate>
问候..:)
Regards..:)