I am confused. Ii do not see how to add an edit template to a gridview. I know how to do it to a formview. I do not even see it as an option. Could you please be more specific? Thanks.
Main Topics
Browse All TopicsI am creating a page to add maintenance technicians to a sql express table. I want to be able to edit a gridview. I have added it and associated my stored procedures with the datasource. The problem is that when I click edit the gridview disappears. Below is my code for the page and the stored procedure.
ASPX Page
##########################
<%@ Page Language="VB" MasterPageFile="~/masters/
<asp:Content ID="Content1" ContentPlaceHolderID="cphM
<h4>Add Technicians...</h4>
<asp:formview datakeynames="id" datasourceid="srcTechs" defaultmode="Insert" id="frmAddTechs" runat="server">
<insertitemtemplate>
First Name:
<asp:textbox id="txtfirst_name" runat="server" text='<%# Bind("first_name") %>'></asp:textbox><br />
Last Name:
<asp:textbox id="txtLastName" runat="server" text='<%# Bind("last_name") %>'></asp:textbox><br />
<asp:linkbutton id="InsertButton" runat="server" causesvalidation="True" commandname="Insert"
text="Insert"></asp:linkbu
<asp:linkbutton id="InsertCancelButton" runat="server" causesvalidation="False" commandname="Cancel"
text="Cancel"></asp:linkbu
</insertitemtemplate>
</asp:formview>
<asp:sqldatasource id="srcTechs" runat="server" connectionstring="<%$ ConnectionStrings:conMaint
insertcommand="sp_insert_t
<insertparameters>
<asp:parameter name="first_name" type="String" />
<asp:parameter name="last_name" type="String" />
</insertparameters>
<updateparameters>
<asp:parameter name="first_name" type="String" />
<asp:parameter name="last_name" type="String" />
<asp:parameter name="email" type="String" />
<asp:parameter name="active" type="Boolean" />
<asp:parameter name="original_id" type="Int32" />
<asp:parameter name="original_first_name"
<asp:parameter name="original_last_name" type="String" />
<asp:parameter name="original_email" type="String" />
<asp:parameter name="original_active" type="Boolean" />
</updateparameters>
<deleteparameters>
<asp:parameter name="original_id" type="Int32" />
<asp:parameter name="original_first_name"
<asp:parameter name="original_last_name" type="String" />
<asp:parameter name="original_email" type="String" />
<asp:parameter name="original_active" type="Boolean" />
</deleteparameters>
</asp:sqldatasource>
<h4>Current Technicians...</h4>
<asp:gridview id="grdTechs" runat="server" e autogeneratecolumns="False
datasourceid="SqlDataSourc
<columns>
<asp:commandfield showeditbutton="True" />
<asp:boundfield datafield="id" headertext="id" insertvisible="False" readonly="True"
sortexpression="id" visible="False" />
<asp:boundfield datafield="first_name" headertext="First Name" sortexpression="first_name
<asp:boundfield datafield="last_name" headertext="Last Name" sortexpression="last_name"
<asp:boundfield datafield="email" headertext="Email Address" sortexpression="email" />
<asp:checkboxfield datafield="active" headertext="Active" sortexpression="active" />
</columns>
<rowstyle font-size="Small" />
<headerstyle font-bold="True" />
</asp:gridview>
<asp:sqldatasource id="SqlDataSource1" runat="server" conflictdetection="Compare
connectionstring="<%$ ConnectionStrings:conMaint
insertcommand="INSERT INTO [tech] ([first_name], [last_name], [email], [active]) VALUES (@first_name, @last_name, @email, @active)"
oldvaluesparameterformatst
updatecommand="UPDATE [tech] SET [first_name] = @first_name, [last_name] = @last_name, [email] = @email, [active] = @active WHERE [id] = @original_id AND [first_name] = @original_first_name AND [last_name] = @original_last_name AND [email] = @original_email AND [active] = @original_active">
<deleteparameters>
<asp:parameter name="original_id" type="Int32" />
<asp:parameter name="original_first_name"
<asp:parameter name="original_last_name" type="String" />
<asp:parameter name="original_email" type="String" />
<asp:parameter name="original_active" type="Boolean" />
</deleteparameters>
<updateparameters>
<asp:parameter name="first_name" type="String" />
<asp:parameter name="last_name" type="String" />
<asp:parameter name="email" type="String" />
<asp:parameter name="active" type="Boolean" />
<asp:parameter name="original_id" type="Int32" />
<asp:parameter name="original_first_name"
<asp:parameter name="original_last_name" type="String" />
<asp:parameter name="original_email" type="String" />
<asp:parameter name="original_active" type="Boolean" />
</updateparameters>
<insertparameters>
<asp:parameter name="first_name" type="String" />
<asp:parameter name="last_name" type="String" />
<asp:parameter name="email" type="String" />
<asp:parameter name="active" type="Boolean" />
</insertparameters>
</asp:sqldatasource>
</asp:Content>
ASPX.VB File
##########################
Partial Class maint_technicians
Inherits System.Web.UI.Page
End Class
Stored Procedure
##########################
ALTER PROCEDURE dbo.sp_update_tech
(
@first_name varchar(50),
@last_name varchar(50),
@email varchar(50),
@active bit,
@Original_id int,
@IsNull_first_name Int,
@Original_first_name varchar(50),
@IsNull_last_name Int,
@Original_last_name varchar(50),
@IsNull_email Int,
@Original_email varchar(50),
@IsNull_active Int,
@Original_active bit,
@id int
)
AS
SET NOCOUNT OFF;
UPDATE [tech] SET [first_name] = @first_name, [last_name] = @last_name, [email] = @email, [active] = @active WHERE (([id] = @Original_id) AND ((@IsNull_first_name = 1 AND [first_name] IS NULL) OR ([first_name] = @Original_first_name)) AND ((@IsNull_last_name = 1 AND [last_name] IS NULL) OR ([last_name] = @Original_last_name)) AND ((@IsNull_email = 1 AND [email] IS NULL) OR ([email] = @Original_email)) AND ((@IsNull_active = 1 AND [active] IS NULL) OR ([active] = @Original_active)));
SELECT id, first_name, last_name, email, active FROM tech WHERE (id = @id)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Well, I suppose you are using Visual Studio 2005.
If so, Right-Click on your GridView and select the menu "Modify the Models" and Column 0 (or any other).
You will see 5 Panels :
ItemTemplate
AlternatingItemTemplate
EditItemTemplate
Header ...
FooterItemTemplate
You can drag drop any control from the toolbox to Edit ItemTemplate area.
Your column must be a Template Field.
You can do it with VWD because it's a part of Visual Studio 2005.
You can also add the EditItemTemplate in your page like this:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="Contac
DeleteMethod="RemoveContac
TypeName="ContactApp.BLL.C
UpdateMethod="UpdateContac
<DeleteParameters>
<asp:Parameter Name="ContactID" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False
OnRowUpdating="GridView1_R
>
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField HeaderText="ContactID" SortExpression="ContactID"
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ContactID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ContactID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contactname" SortExpression="Contactnam
<EditItemTemplate>
<asp:TextBox
ID="txtContactName"
runat="server"
Text='<%# Bind("Contactname") %>' OnTextChanged="txtContactn
<asp:RequiredFieldValidato
ID="RequiredFieldValidator
runat="server"
ControlToValidate="txtCont
ErrorMessage="RequiredFiel
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Contactname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ContactAge" SortExpression="ContactAge
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ContactAge") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ContactAge") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ContactCategor
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("ContactCategoryID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("ContactCategoryID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Okay.... I scrapped what I had before. Now I have the following and get the same thing.
<%@ Page Language="VB" MasterPageFile="~/masters/
<asp:Content ID="Content1" ContentPlaceHolderID="cphM
<asp:gridview id="grdSubPriorities" runat="server" allowsorting="True" autogeneratecolumns="False
<columns>
<asp:commandfield showeditbutton="True" />
<asp:templatefield headertext="Id">
<itemtemplate>
<%# Eval("id")%>
</itemtemplate>
<edititemtemplate><%# Eval("id")%>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Sub Priority">
<itemtemplate>
<%# Eval("desc")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtDesc" runat="server" text='<%# Bind("desc") %>'></asp:textbox>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Weight Factor">
<itemtemplate>
<%# Eval("weight")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtWeight" runat="server" text='<%# Bind("weight") %>'></asp:textbox>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Priority">
<itemtemplate>
<%# Eval("priority")%>
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist id="drpPriority" runat="server" datasourceid="srcPriority"
datavaluefield="id" selectedvalue='<%# Bind("priority_id") %>' autopostback="True">
</asp:dropdownlist>
</edititemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
<asp:sqldatasource id="srcSubPriority" runat="server" conflictdetection="Compare
connectionstring="<%$ ConnectionStrings:conMaint
oldvaluesparameterformatst
updatecommand="UPDATE [sub_priority] SET [desc] = @desc, [priority_id] = @priority_id, [weight] = @weight WHERE [id] = @original_id">
<updateparameters>
<asp:parameter name="desc" type="String" />
<asp:parameter name="priority_id" type="Int32" />
<asp:parameter name="weight" type="Byte" />
<asp:parameter name="original_id" type="Int32" />
</updateparameters>
</asp:sqldatasource>
<asp:sqldatasource id="srcPriority" runat="server" connectionstring="<%$ ConnectionStrings:conMaint
selectcommand="SELECT [id], [desc] FROM [priority]"></asp:sqldatas
</asp:Content>
Business Accounts
Answer for Membership
by: nouloukPosted on 2007-10-23 at 22:11:01ID: 20136445
Hi bhorlings,
It seems you only add an Item Template. You need to create an EditItem Template.
In fact, your GridView switches to Edit Mode, but if there is no control, it shows nothing.
Hope this helps.