Hi mpaine,
From your description, you're using the ASP.NET DetailsView control for
database record inserting. However, you encountered some problems to modify
some control in the Detailsview after inserting, correct?
According to the aspx template and code snippet you provided, I have the
following question need to confirm:
1. You're perform inserting in the Detailsview, however, the template you
used (for the template column) is "ItemTempla te", why didn't you use the
"InsertItemTemp late" since that's the correct template for putting markup
displayed at insert mode:
<<<<<<<<<<<
<InsertItemTemp late>
this is insert template.<br />
<asp:DropDownLi st ID="dv_ddlComma nd"
runat="server" AutoPostBack="f alse">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"> </asp:ListItem>
</asp:DropDownLis t>
</InsertItemTempl ate>
</asp:TemplateFie ld>
>>>>>>>>>>>>> >>
2. For inserting, "Item_Inserting " event fires before the inserting is done
to database. If you want the event fired after record has been correctly
inserted, you should use "Item_Inser ted" event.
Also, I'm not sure why will you need to modify the dropdownlist after
inserting, by default, after inserting, the DetailsView will change its
mode to its default template so that the controls are get reloaded(that may
cause any changes you made in the above events not be persisted). Are you
going to display some message or mark some flag to let the user know that
the item has been inserted? If so, I think you can put an external Label
control on the page and set some message to the Label in the DetailsView's
"Item_Inser ted" event. e.g.
<<<<<<<<<<<<<
protected void DetailsView1_It emInserted(obje ct sender,
DetailsViewInse rtedEventArgs e)
{
lblMessage.Text = "New Item has been inserted!";
}
>>>>>>>>>>>>> >>
Please feel free to let me know if there is any particular requirement or
concerns in your scenario.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: =?Utf-8?B?bXBhaW5l?= <mp****@communi ty.nospam>
References: <3E************ *************** *******@microso ft.com>
Subject: RE: Why does DetailsView become read-only after insert?
Date: Mon, 9 Jun 2008 21:28:03 -0700
>
oops, I guess I should have mentioned that the sample should set
ddl.BackColo r = Color.Red, within Page_Load(), after the insert occurs but
it
>doesn't.
--
msdn premium subscriber
"mpaine" wrote:
>Hello,
I am completely lost as to why I can't update a DropDownList inside a
DetailsView after I perform an insert into an object datasource. I
tried to
>simply it down to the core demostration:
default.aspx :
<%@ Page Language="C#" AutoEventWireup ="true"
CodeBehind="Def ault.aspx.cs"
>Inherits="Test DetailsView.Def ault" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<form id="form1" runat="server">
<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
DataObjectType Name="TestDetai lsView.User"
TypeName="TestD etailsView.User Adapter"
InsertMethod="I nsertUser"
>/>
<asp:DetailsVie w ID="DetailsView 1" runat="server"
AutoGenerateRo ws="False" DataSourceID="O bjectDataSource 1"
DefaultMode="In sert"
OnItemInserting ="DetailsView1_ ItemInserting">
> <Fields>
<asp:TemplateFi eld HeaderText="Com mand" runat="server">
<ItemTemplate >
<asp:DropDownLi st ID="dv_ddlComma nd"
runat="server"
>AutoPostBack=" false">
<asp:ListItem Text="add"
Value="add"> </asp:ListItem>
<asp:ListItem Text="delete"
Value="delete" ></asp:ListItem>
</asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:CommandFie ld ButtonType="But ton"
ShowInsertButt on="True" InsertText="Add "></asp:CommandFiel d>
</Fields>
</asp:DetailsView >
</form>
</body>
</html>
default.aspx.c s:
using System;
using System.Drawing;
using System.Web.UI.W ebControls;
namespace TestDetailsView
{
public class User
{
private string _Command = "new";
public string Command
{
get { return _Command; }
set { _Command = value; }
}
public User() { }
public User(string Command)
{
this.Command = Command;
}
}
public class UserAdapter
{
public void InsertUser(User User)
{
}
}
public partial class Default : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
DropDownList ddl =
(DropDownList) DetailsView1.Fi ndControl("dv_d dlCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}
protected void DetailsView1_It emInserting(obj ect sender,
DetailsViewIns ertEventArgs e)
{
DropDownList ddl =
(DropDownList) DetailsView1.Fi ndControl("dv_d dlCommand");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedVal ue;
ddl.BackColor = Color.Red;
}
}
}
}
Any help would be extremely helpful.
Thank you!
--
msdn premium subscriber