Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Why does DetailsView become read-only after insert?

Reply
Thread Tools

Why does DetailsView become read-only after insert?

 
 
mpaine
Guest
Posts: n/a
 
      06-10-2008
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"
/>

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

<asp:CommandField ButtonType="Button"
ShowInsertButton="True" InsertText="Add"></asp:CommandField>
</Fields>
</aspetailsView>
</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
 
Reply With Quote
 
 
 
 
mpaine
Guest
Posts: n/a
 
      06-10-2008
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"
> />
>
> <aspetailsView ID="DetailsView1" runat="server"
> AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
> DefaultMode="Insert" OnItemInserting="DetailsView1_ItemInserting">
> <Fields>
> <asp:TemplateField HeaderText="Command" runat="server">
> <ItemTemplate>
> <aspropDownList ID="dv_ddlCommand" runat="server"
> AutoPostBack="false">
> <asp:ListItem Text="add"
> Value="add"></asp:ListItem>
> <asp:ListItem Text="delete"
> Value="delete"></asp:ListItem>
> </aspropDownList>
> </ItemTemplate>
> </asp:TemplateField>
>
> <asp:CommandField ButtonType="Button"
> ShowInsertButton="True" InsertText="Add"></asp:CommandField>
> </Fields>
> </aspetailsView>
> </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

 
Reply With Quote
 
 
 
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      06-10-2008
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 />
<aspropDownList ID="dv_ddlCommand"
runat="server" AutoPostBack="false">
<asp:ListItem Text="add"
Value="add"></asp:ListItem>
<asp:ListItem Text="delete"
Value="delete"></asp:ListItem>
</aspropDownList>
</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:
http://www.velocityreviews.com/forums/(E-Mail Removed).

==================================================
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?= <(E-Mail Removed)>
>References: <(E-Mail Removed)>
>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"
>> />
>>
>> <aspetailsView ID="DetailsView1" runat="server"
>> AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
>> DefaultMode="Insert"

OnItemInserting="DetailsView1_ItemInserting">
>> <Fields>
>> <asp:TemplateField HeaderText="Command" runat="server">
>> <ItemTemplate>
>> <aspropDownList ID="dv_ddlCommand"

runat="server"
>> AutoPostBack="false">
>> <asp:ListItem Text="add"
>> Value="add"></asp:ListItem>
>> <asp:ListItem Text="delete"
>> Value="delete"></asp:ListItem>
>> </aspropDownList>
>> </ItemTemplate>
>> </asp:TemplateField>
>>
>> <asp:CommandField ButtonType="Button"
>> ShowInsertButton="True" InsertText="Add"></asp:CommandField>
>> </Fields>
>> </aspetailsView>
>> </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

>


 
Reply With Quote
 
mpaine
Guest
Posts: n/a
 
      06-10-2008
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>
<aspropDownList 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>
</aspropDownList>
</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 />
> <aspropDownList ID="dv_ddlCommand"
> runat="server" AutoPostBack="false">
> <asp:ListItem Text="add"
> Value="add"></asp:ListItem>
> <asp:ListItem Text="delete"
> Value="delete"></asp:ListItem>
> </aspropDownList>
> </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:
> (E-Mail Removed).
>
> ==================================================
> 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?= <(E-Mail Removed)>
> >References: <(E-Mail Removed)>
> >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"
> >> />
> >>
> >> <aspetailsView ID="DetailsView1" runat="server"
> >> AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
> >> DefaultMode="Insert"

> OnItemInserting="DetailsView1_ItemInserting">
> >> <Fields>
> >> <asp:TemplateField HeaderText="Command" runat="server">
> >> <ItemTemplate>
> >> <aspropDownList ID="dv_ddlCommand"

> runat="server"
> >> AutoPostBack="false">
> >> <asp:ListItem Text="add"
> >> Value="add"></asp:ListItem>
> >> <asp:ListItem Text="delete"
> >> Value="delete"></asp:ListItem>
> >> </aspropDownList>
> >> </ItemTemplate>
> >> </asp:TemplateField>
> >>
> >> <asp:CommandField ButtonType="Button"
> >> ShowInsertButton="True" InsertText="Add"></asp:CommandField>
> >> </Fields>
> >> </aspetailsView>
> >> </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

> >

>
>

 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      06-11-2008
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:
(E-Mail Removed).

==================================================
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?= <(E-Mail Removed)>
>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>
> <aspropDownList 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>
> </aspropDownList>
> </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 />
>> <aspropDownList ID="dv_ddlCommand"
>> runat="server" AutoPostBack="false">
>> <asp:ListItem Text="add"
>> Value="add"></asp:ListItem>
>> <asp:ListItem Text="delete"
>> Value="delete"></asp:ListItem>
>> </aspropDownList>
>> </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:
>> (E-Mail Removed).
>>
>> ==================================================
>> 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?= <(E-Mail Removed)>
>> >References: <(E-Mail Removed)>
>> >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"
>> >> />
>> >>
>> >> <aspetailsView ID="DetailsView1" runat="server"
>> >> AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
>> >> DefaultMode="Insert"

>> OnItemInserting="DetailsView1_ItemInserting">
>> >> <Fields>
>> >> <asp:TemplateField HeaderText="Command"

runat="server">
>> >> <ItemTemplate>
>> >> <aspropDownList ID="dv_ddlCommand"

>> runat="server"
>> >> AutoPostBack="false">
>> >> <asp:ListItem Text="add"
>> >> Value="add"></asp:ListItem>
>> >> <asp:ListItem Text="delete"
>> >> Value="delete"></asp:ListItem>
>> >> </aspropDownList>
>> >> </ItemTemplate>
>> >> </asp:TemplateField>
>> >>
>> >> <asp:CommandField ButtonType="Button"
>> >> ShowInsertButton="True" InsertText="Add"></asp:CommandField>
>> >> </Fields>
>> >> </aspetailsView>
>> >> </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
>> >

>>
>>

>


 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      06-13-2008
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 Removed).

==================================================
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
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Become The master in computer hardware to become successfull shilla Computer Security 1 01-22-2011 06:19 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM



Advertisments