Why does DetailsView become read-only after insert?

M

mpaine

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_ddlCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

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

}
}


Any help would be extremely helpful.


Thank you!
 
M

mpaine

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.
 
S

Steven Cheng [MSFT]

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>


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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
From: =?Utf-8?B?bXBhaW5l?= <[email protected]>
References: <[email protected]>
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 said:
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_ddlCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

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

}
}


Any help would be extremely helpful.


Thank you!
 
M

mpaine

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_ddlCommand");
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 said:
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>


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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
From: =?Utf-8?B?bXBhaW5l?= <[email protected]>
References: <[email protected]>
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 said:
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_ddlCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

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

}
}


Any help would be extremely helpful.


Thank you!
 
S

Steven Cheng [MSFT]

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
rolesprotected 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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

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

--------------------
From: =?Utf-8?B?bXBhaW5l?= <[email protected]>
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"> said:
<asp:ListItem Text="reschedule"
Value="reschedule"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

and my code behind uses:

DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dv_ddlCommand");
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 said:
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>


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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
From: =?Utf-8?B?bXBhaW5l?= <[email protected]>
References: <[email protected]>
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


:

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_ddlCommand");
if (ddl != null)
{
ddl.BackColor = Color.Red;
}
}

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

}
}


Any help would be extremely helpful.


Thank you!
 
S

Steven Cheng [MSFT]

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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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
rolesprotected 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top