473,748 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does DetailsView become read-only after insert?

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="TestD etailsView.Defa ult" %>
<!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"
DataObjectTypeN ame="TestDetail sView.User"
TypeName="TestD etailsView.User Adapter" InsertMethod="I nsertUser"
/>

<asp:DetailsVie w ID="DetailsView 1" runat="server"
AutoGenerateRow s="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="f alse">
<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"
ShowInsertButto n="True" InsertText="Add "></asp:CommandFiel d>
</Fields>
</asp:DetailsView >
</form>
</body>
</html>

default.aspx.cs :

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)D etailsView1.Fin dControl("dv_dd lCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

protected void DetailsView1_It emInserting(obj ect sender,
DetailsViewInse rtEventArgs e)
{
DropDownList ddl =
(DropDownList)D etailsView1.Fin dControl("dv_dd lCommand");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedVal ue;
ddl.BackColor = Color.Red;
}
}

}
}
Any help would be extremely helpful.
Thank you!

--
msdn premium subscriber
Jun 27 '08 #1
5 3462
oops, I guess I should have mentioned that the sample should set
ddl.BackColor = 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="TestD etailsView.Defa ult" %>
<!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"
DataObjectTypeN ame="TestDetail sView.User"
TypeName="TestD etailsView.User Adapter" InsertMethod="I nsertUser"
/>

<asp:DetailsVie w ID="DetailsView 1" runat="server"
AutoGenerateRow s="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="f alse">
<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"
ShowInsertButto n="True" InsertText="Add "></asp:CommandFiel d>
</Fields>
</asp:DetailsView >
</form>
</body>
</html>

default.aspx.cs :

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)D etailsView1.Fin dControl("dv_dd lCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

protected void DetailsView1_It emInserting(obj ect sender,
DetailsViewInse rtEventArgs e)
{
DropDownList ddl =
(DropDownList)D etailsView1.Fin dControl("dv_dd lCommand");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedVal ue;
ddl.BackColor = Color.Red;
}
}

}
}
Any help would be extremely helpful.
Thank you!

--
msdn premium subscriber
Jun 27 '08 #2
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
Jun 27 '08 #3
Thanks for the response! I tried changing things as you mentioned, but I
guess I still have the same problem. The idea is that I am using a
DetailsView as an insert into a collection class. I want to reuse the same
detailsview for multiple inserts.

What I am trying to do is hide/unhide the DropDownList for certain types of
users (using Membership Roles). The problem is that after the insert, the
DropDownList becomes the default (either hidden always or not hidden always)
and I can't dynamically change it after the insert (as I was trying to
demonstrate using the BackColor).

For example, in my real code, I do the following:

<asp:TemplateFi eld HeaderText="Com mand" runat="server" Visible="true">
<ItemTemplate >
<asp:DropDownLi st ID="dv_ddlComma nd" runat="server"
AutoPostBack="f alse" Enabled="false"
Visible="false" >
<asp:ListItem Text="add" Value="add"></asp:ListItem>
<asp:ListItem Text="reschedul e"
Value="reschedu le"></asp:ListItem>
</asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateFie ld>

and my code behind uses:

DropDownList ddl =
(DropDownList)D etailsView1.Fin dControl("dv_dd lCommand");
if (ddl != null)
{
ddl.Enabled = User.IsInRole(" clk_admin");
ddl.Visible = ddl.Enabled;
}

...here, when I step debug through it, ddl.Enabled and ddl.Visible change but
the changes aren't persisted during the Render cycle.

Do you have any suggestions? Perhaps I am using the wrong thing here --
maybe there is something better to use than a DetailsView, although it does
work nicely otherwise.

Thanks again!
Michael
--
msdn premium subscriber
"Steven Cheng [MSFT]" wrote:
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.BackColor = 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="TestD etailsView.Defa ult" %>
<!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"
DataObjectTypeN ame="TestDetail sView.User"
TypeName="TestD etailsView.User Adapter"
InsertMethod="I nsertUser"
/>

<asp:DetailsVie w ID="DetailsView 1" runat="server"
AutoGenerateRow s="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="f alse">
<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"
ShowInsertButto n="True" InsertText="Add "></asp:CommandFiel d>
</Fields>
</asp:DetailsView >
</form>
</body>
</html>

default.aspx.cs :

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)D etailsView1.Fin dControl("dv_dd lCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

protected void DetailsView1_It emInserting(obj ect sender,
DetailsViewInse rtEventArgs e)
{
DropDownList ddl =
(DropDownList)D etailsView1.Fin dControl("dv_dd lCommand");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedVal ue;
ddl.BackColor = Color.Red;
}
}

}
}
Any help would be extremely helpful.
Thank you!

--
msdn premium subscriber

Jun 27 '08 #4
Hi Michael,

If what you want to do is adjust the visiblity of the Dropdownlist depend
on the current user's roles. I think you should use DetailsView's
"ItemCreate d" event to check the user roles and set DropDownList's
visiblity. The "ItemCreate d" event will fire in each page request and when
the DetailsView has just populated its control collection. Here is a
simple example to do this:

#here is my test code check the querystring parameter to determine the
visibility, for your case, you can change it to check the currnet user's
roles
>>>>>>>>>>>>>>> >>>>>>>>>>
protected void DetailsView1_It emCreated(objec t sender, EventArgs e)
{

DropDownList ddl = DetailsView1.Fi ndControl("dv_d dlCommand") as
DropDownList;
if (ddl != null)
{
if(string.IsNul lOrEmpty(Reques t.QueryString["enable"]))
{
ddl.Visible = false;
}
}
}
>>>>>>>>>>>>>>> >>>>>>>>>>>>
Hope this helps.

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.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: =?Utf-8?B?bXBhaW5l?= <mp****@communi ty.nospam>
Subject: RE: Why does DetailsView become read-only after insert?
Date: Tue, 10 Jun 2008 09:57:01 -0700

Thanks for the response! I tried changing things as you mentioned, but I
guess I still have the same problem. The idea is that I am using a
DetailsView as an insert into a collection class. I want to reuse the
same
>detailsview for multiple inserts.

What I am trying to do is hide/unhide the DropDownList for certain types
of
>users (using Membership Roles). The problem is that after the insert, the
DropDownList becomes the default (either hidden always or not hidden
always)
>and I can't dynamically change it after the insert (as I was trying to
demonstrate using the BackColor).

For example, in my real code, I do the following:

<asp:TemplateF ield HeaderText="Com mand" runat="server" Visible="true">
<ItemTemplate >
<asp:DropDownLi st ID="dv_ddlComma nd" runat="server"
AutoPostBack=" false" Enabled="false"
Visible="false" >
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="reschedul e"
Value="resched ule"></asp:ListItem>
</asp:DropDownLis t>
</ItemTemplate>
</asp:TemplateFie ld>

and my code behind uses:

DropDownList ddl =
(DropDownList) DetailsView1.Fi ndControl("dv_d dlCommand");
if (ddl != null)
{
ddl.Enabled = User.IsInRole(" clk_admin");
ddl.Visible = ddl.Enabled;
}

..here, when I step debug through it, ddl.Enabled and ddl.Visible change
but
>the changes aren't persisted during the Render cycle.

Do you have any suggestions? Perhaps I am using the wrong thing here --
maybe there is something better to use than a DetailsView, although it
does
>work nicely otherwise.

Thanks again!
Michael
--
msdn premium subscriber
"Steven Cheng [MSFT]" wrote:
>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
"InsertItemTem plate" 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="serve r" 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_Inserted " event. e.g.

<<<<<<<<<<<< <
protected void DetailsView1_It emInserted(obje ct sender,
DetailsViewIns ertedEventArgs 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="De fault.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=" InsertUser"
>/>

<asp:DetailsVie w ID="DetailsView 1" runat="server"
AutoGenerateRo ws="False" DataSourceID="O bjectDataSource 1"
DefaultMode="In sert"
OnItemInsertin g="DetailsView1 _ItemInserting" >
> <Fields>
<asp:TemplateFi eld HeaderText="Com mand"
runat="server">
> <ItemTemplate >
<asp:DropDownLi st ID="dv_ddlComma nd"
runat="serve r"
>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

Jun 27 '08 #5
Hi Michael,

Any further progress on this or does the information in my last reply help
you some?

If there is anything else we can help, please feel free to let me know.

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.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>Date: Wed, 11 Jun 2008 04:58:07 GMT
Subject: RE: Why does DetailsView become read-only after insert?
>
Hi Michael,

If what you want to do is adjust the visiblity of the Dropdownlist depend
on the current user's roles. I think you should use DetailsView's
"ItemCreated " event to check the user roles and set DropDownList's
visiblity. The "ItemCreate d" event will fire in each page request and when
the DetailsView has just populated its control collection. Here is a
simple example to do this:

#here is my test code check the querystring parameter to determine the
visibility, for your case, you can change it to check the currnet user's
roles
>>>>>>>>>>>>>>> >>>>>>>>>>>
protected void DetailsView1_It emCreated(objec t sender, EventArgs e)
{

DropDownList ddl = DetailsView1.Fi ndControl("dv_d dlCommand") as
DropDownList ;
if (ddl != null)
{
if(string.IsNul lOrEmpty(Reques t.QueryString["enable"]))
{
ddl.Visible = false;
}
}
}
>>>>>>>>>>>>>>> >>>>>>>>>>>>>

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
8703
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press update after making changes, but I don't want that update button. How can I get the updated object when the user presses one of my other action buttons?
1
4439
by: sck10 | last post by:
Hello, I am trying to change a value when a user goes into edit mode on a DetailsView control. I am trying to use the following, but can not figure out how to get to the bound field ("MyBoundField") to set its new value. Any help with this would be appreciated. Sub EmployeeDetailView_ModeChanged(ByVal sender As Object, ByVal e As EventArgs) Select Case CustomerDetailView.CurrentMode
4
16059
by: Frits van Soldt | last post by:
Hello, I hope somebody can help me with this! I have 2 listboxes in the edititemtemplate of a detailsview. In the databound event of the detailsview I would like to fill the listboxes programmatically (not through databinding). If I use detailsview.findcontrol(controlname) then an empty object is returned. How can I address these controls? Thank you for your time.
3
14582
by: Jason | last post by:
Anyone know how to make the text wrap in a text box of a DetailsView?
2
6249
by: nolan | last post by:
I have an asp.net 2.0 page with a gridview and detailsview on the same page set up in a master-details scenario. The gridview and detailsview have separate SQL data sources. The user enters search criteria in a text box and clicks a find button to initially populate the gridview with items of interest. I have added a select button to my gridview and when the user clicks the button the detailsview is populated perfectly. However, I also...
1
4273
by: Corey B | last post by:
I have a page with a DetailsView control and a SQLDataSource control. The SQLDataSource control is connected to an Access database. Everything works fine. Now I want to change the back end database from Access to SQL Server. So I go in to the SQLDataSource and modify it to connect to the SQL Server database. No problem. However, the DetailsView control does not seem to pick up the changes. When I click on the little shortcut menu (not...
2
11634
by: mike | last post by:
I have a page with a LoginView which contains a Gridview and a DetailsView, each in its own UpdatePanel The problem that I am experiencing is that when I select a record in the Gridview (using a SelectButton), the selected record is shown in the DetailsView, which is correct - however, when I choose "Update" on the DetailsView I am presented with the EditItemTemplate which contains the first record in the DetailsDataSource. The code...
3
1988
by: Martin Frey | last post by:
Hello guys, im new to asp.net and im trying to get me used to it. I've managed to create webpages with detailviews, databinding and datasources. Adding or inserting data went very well and, after a while, very fast. Now i ran into a problem with accessing the data. I need to send an email to the administrator with the data the user has selected instead of calling the update method. Everything i've build up via the designer or the...
0
1087
by: info | last post by:
Hi guys. I have been thrown into the deep end. I don't know ASP, and with my C# development, I haven't used data aware controls. I am swimming OK so far (Image uploaded completed, XML/XSL menu created for the Master Page) but now now I have been asked to create a
0
1476
by: Dan | last post by:
Hi, I have a detailsview with two fields: in editmode, one is a textbox and the other is a dropdownlist. i want to update both fields using the detailsview. My problem: when clicking on the edit button, the modified text in the textbox is effectively updated in the table, but instead of updating the chosen value of the dropdownlist, the field in the table becomes empty (old value is updated by nothing). The items of the dropdownlist...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.