472,778 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,778 software developers and data experts.

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="Default.aspx.cs"
Inherits="TestDetailsView.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<form id="form1" runat="server">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="TestDetailsView.User"
TypeName="TestDetailsView.UserAdapter" InsertMethod="InsertUser"
/>

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
DefaultMode="Insert" OnItemInserting="DetailsView1_ItemInserting">
<Fields>
<asp:TemplateField HeaderText="Command" runat="server">
<ItemTemplate>
<asp:DropDownList ID="dv_ddlCommand" runat="server"
AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

<asp:CommandField ButtonType="Button"
ShowInsertButton="True" InsertText="Add"></asp:CommandField>
</Fields>
</asp:DetailsView>
</form>
</body>
</html>

default.aspx.cs:

using System;
using System.Drawing;
using System.Web.UI.WebControls;

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.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlComm and");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

protected void DetailsView1_ItemInserting(object sender,
DetailsViewInsertEventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlComm and");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedValue;
ddl.BackColor = Color.Red;
}
}

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

--
msdn premium subscriber
Jun 27 '08 #1
5 3378
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="Default.aspx.cs"
Inherits="TestDetailsView.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<form id="form1" runat="server">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="TestDetailsView.User"
TypeName="TestDetailsView.UserAdapter" InsertMethod="InsertUser"
/>

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
DefaultMode="Insert" OnItemInserting="DetailsView1_ItemInserting">
<Fields>
<asp:TemplateField HeaderText="Command" runat="server">
<ItemTemplate>
<asp:DropDownList ID="dv_ddlCommand" runat="server"
AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

<asp:CommandField ButtonType="Button"
ShowInsertButton="True" InsertText="Add"></asp:CommandField>
</Fields>
</asp:DetailsView>
</form>
</body>
</html>

default.aspx.cs:

using System;
using System.Drawing;
using System.Web.UI.WebControls;

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.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlComm and");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

protected void DetailsView1_ItemInserting(object sender,
DetailsViewInsertEventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlComm and");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedValue;
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 "ItemTemplate", why didn't you use the
"InsertItemTemplate" since that's the correct template for putting markup
displayed at insert mode:

<<<<<<<<<<<
<InsertItemTemplate>
this is insert template.<br />
<asp:DropDownList ID="dv_ddlCommand"
runat="server" AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
>>>>>>>>>>>>>>>

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_Inserted" 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_ItemInserted(object sender,
DetailsViewInsertedEventArgs 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****@microsoft.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****@community.nospam>
References: <3E**********************************@microsoft.co m>
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="Default.aspx.cs"
>Inherits="TestDetailsView.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<form id="form1" runat="server">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="TestDetailsView.User"
TypeName="TestDetailsView.UserAdapter"
InsertMethod="InsertUser"
>/>

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
DefaultMode="Insert"
OnItemInserting="DetailsView1_ItemInserting">
> <Fields>
<asp:TemplateField HeaderText="Command" runat="server">
<ItemTemplate>
<asp:DropDownList ID="dv_ddlCommand"
runat="server"
>AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

<asp:CommandField ButtonType="Button"
ShowInsertButton="True" InsertText="Add"></asp:CommandField>
</Fields>
</asp:DetailsView>
</form>
</body>
</html>

default.aspx.cs:

using System;
using System.Drawing;
using System.Web.UI.WebControls;

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.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCom mand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

protected void DetailsView1_ItemInserting(object sender,
DetailsViewInsertEventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCom mand");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedValue;
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:TemplateField HeaderText="Command" runat="server" Visible="true">
<ItemTemplate>
<asp:DropDownList ID="dv_ddlCommand" runat="server"
AutoPostBack="false" Enabled="false"
Visible="false">
<asp:ListItem Text="add" Value="add"></asp:ListItem>
<asp:ListItem Text="reschedule"
Value="reschedule"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

and my code behind uses:

DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlComm and");
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 "ItemTemplate", why didn't you use the
"InsertItemTemplate" since that's the correct template for putting markup
displayed at insert mode:

<<<<<<<<<<<
<InsertItemTemplate>
this is insert template.<br />
<asp:DropDownList ID="dv_ddlCommand"
runat="server" AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
>>>>>>>>>>>>>>


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_Inserted" 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_ItemInserted(object sender,
DetailsViewInsertedEventArgs 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****@microsoft.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****@community.nospam>
References: <3E**********************************@microsoft.co m>
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="Default.aspx.cs"
Inherits="TestDetailsView.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<form id="form1" runat="server">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="TestDetailsView.User"
TypeName="TestDetailsView.UserAdapter"
InsertMethod="InsertUser"
/>

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
DefaultMode="Insert"
OnItemInserting="DetailsView1_ItemInserting">
<Fields>
<asp:TemplateField HeaderText="Command" runat="server">
<ItemTemplate>
<asp:DropDownList ID="dv_ddlCommand"
runat="server"
AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

<asp:CommandField ButtonType="Button"
ShowInsertButton="True" InsertText="Add"></asp:CommandField>
</Fields>
</asp:DetailsView>
</form>
</body>
</html>

default.aspx.cs:

using System;
using System.Drawing;
using System.Web.UI.WebControls;

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.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlComm and");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

protected void DetailsView1_ItemInserting(object sender,
DetailsViewInsertEventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlComm and");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedValue;
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
"ItemCreated" event to check the user roles and set DropDownList's
visiblity. The "ItemCreated" 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_ItemCreated(object sender, EventArgs e)
{

DropDownList ddl = DetailsView1.FindControl("dv_ddlCommand") as
DropDownList;
if (ddl != null)
{
if(string.IsNullOrEmpty(Request.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****@microsoft.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****@community.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:TemplateField HeaderText="Command" runat="server" Visible="true">
<ItemTemplate>
<asp:DropDownList ID="dv_ddlCommand" runat="server"
AutoPostBack="false" Enabled="false"
Visible="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="reschedule"
Value="reschedule"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

and my code behind uses:

DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCom mand");
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 "ItemTemplate", why didn't you use the
"InsertItemTemplate" since that's the correct template for putting
markup
>displayed at insert mode:

<<<<<<<<<<<
<InsertItemTemplate>
this is insert template.<br />
<asp:DropDownList ID="dv_ddlCommand"
runat="server" AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
>>>>>>>>>>>>>>>


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_Inserted" 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_ItemInserted(object sender,
DetailsViewInsertedEventArgs 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****@microsoft.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****@community.nospam>
References: <3E**********************************@microsoft.co m>
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="Default.aspx.cs"
>Inherits="TestDetailsView.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<form id="form1" runat="server">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="TestDetailsView.User"
TypeName="TestDetailsView.UserAdapter"
InsertMethod="InsertUser"
>/>

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
DefaultMode="Insert"
OnItemInserting="DetailsView1_ItemInserting">
> <Fields>
<asp:TemplateField HeaderText="Command"
runat="server">
> <ItemTemplate>
<asp:DropDownList ID="dv_ddlCommand"
runat="server"
>AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

<asp:CommandField ButtonType="Button"
ShowInsertButton="True" InsertText="Add"></asp:CommandField>
</Fields>
</asp:DetailsView>
</form>
</body>
</html>

default.aspx.cs:

using System;
using System.Drawing;
using System.Web.UI.WebControls;

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.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCom mand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

protected void DetailsView1_ItemInserting(object sender,
DetailsViewInsertEventArgs e)
{
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCom mand");
if (ddl != null)
{
e.Values["Command"] = ddl.SelectedValue;
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****@microsoft.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 "ItemCreated" 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_ItemCreated(object sender, EventArgs e)
{

DropDownList ddl = DetailsView1.FindControl("dv_ddlCommand") as
DropDownList;
if (ddl != null)
{
if(string.IsNullOrEmpty(Request.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
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...
1
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...
4
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...
3
by: Jason | last post by:
Anyone know how to make the text wrap in a text box of a DetailsView?
2
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...
1
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...
2
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...
3
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...
0
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...
0
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...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.