Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Reusing same DetailsView for both Inserting and Editing

Thread Tools

Reusing same DetailsView for both Inserting and Editing

David Ching
Posts: n/a
Please forgive the cross-post, but I just found this newsgroup, and I think
it is more relevant than microsoft.public.dotnet.framework.aspnet.

Newbie question here. I have a GridView where I show all the records in my
table. I have Edit links in each row to edit that row, and also a button to
Insert a new record. In both cases, I'd like to popup a <div> containing a
DetailsView to specify the record data. The DetailsView has a DefaultMode
property that can be set to Inserting or Editing, so it seems to be meant to
be used for both. Yet I have not figured out how to use the same
DetailsView for both.

The <div> containing the DetailsView is popped up when the Insert button is
clicked as per this JavaScript:
onclick="document.getElementById('divAdd').style.d isplay='block';return

or when an Edit link is clicked:

protected void grdMaster_RowCreated(object sender, GridViewRowEventArgs
if (e.Row.RowType == DataControlRowType.DataRow)
LinkButton lnkEdit = (LinkButton)e.Row.Cells[0].Controls[0];
lnkEdit.Attributes["onclick"] =
"document.getElementById('divAdd').style.display=' block';return false;";

The <div> is :

<div id="divAdd" class="popupWindow">
<h3>Edit Project</h3>
Runat="server" AutoGenerateRows="False" DataKeyNames="ProjectId">
<asp:boundfield DataField="ProjectName" HeaderText="Project Name"/>

<asp:TemplateField HeaderText="Client Name">
<aspropDownList ID="DropDownList1"
SelectedValue='<%# Bind("ClientId")%>'

<asp:boundfield DataField="ProjectPONumber" HeaderText="PO Number"/>

I have verified that this <div> works for the Edit case! It also works for
the Insert case, if I change these lines:

<h3>Edit Project</h3>


<h3>Add Project</h3>

But how can I set these programatically depending on whether an Edit link is
clicked, or the Insert button is clicked? All the examples in the excellent
"ASP.NET 2.0 Unleashed" by Stephen Walther have 2
<div>, one for the Edit, and another one for the Insert. But this seems
wasteful and error-prone because only the above 2 lines are different. Is
there any way to use just one <div> for both Edit and Insert?

Thanks a bunch,

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reusing function signature for both a function pointer and function. daniel rich C Programming 5 11-14-2012 04:03 PM
Inserting from DetailsView and associated Child Records Tyler Lynch ASP .Net Web Controls 1 12-08-2007 07:38 PM
Reusing same DetailsView for both Inserting and Editing David Ching ASP .Net 0 08-29-2007 09:17 PM
Problems with Walkthrough: Editing and Inserting Data in Web Pages with the DetailsView Web Server Control" tom c ASP .Net 0 09-19-2006 10:11 PM
Reusing a user control within the same application STom ASP .Net Building Controls 0 08-17-2003 11:16 AM