if (e.NewMode == DetailsViewMode.Edit)
{
DetailsView1.ChangeMode(DetailsViewMode.Edit);
}
if (e.NewMode == DetailsViewMode.Insert)
{
DetailsView1.ChangeMode(DetailsViewMode.Insert);
}
if (e.NewMode == DetailsViewMode.ReadOnly)
{
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}
}
Now, when I click on edit or insert and trace, the program hits the right event, but I have to hit the button twice for the control to change mode. Even when it does change mode, regardless of which control I hit, the program will randomly decide if it is going
to go into edit mode or update mode. So I might hit update and get the insert mode, or vice versa.
When in either of these modes, I have to press cancel twice to return to readonly mode.....pretty frustrating.
Changing the mode of current DetailsView doesn't require any additional processing. Are you doing something beyond what you've shown in your original post?
I have the same problem which I have been fighting with all day and can't work out. I have to click Edit and Cancel twice for them to do their action. The first and second click are calling the ModeChanging method so I assume there is something wrong with my
code and the same with justB's code.
If I don't put in the ModeChanging event implementation I get an exception:
"The DetailsView 'dvwWorkItem' fired event ModeChanging which wasn't handled."
I do intend on adding other custom code into this method because certain actions need to happen when you start editing or inserting.
Here is the code I have so far:
protected void dvwWorkItem_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
if (e.NewMode == DetailsViewMode.Edit)
{
dvwWorkItem.ChangeMode(DetailsViewMode.Edit);
}
else if (e.NewMode == DetailsViewMode.ReadOnly)
{
if (e.CancelingEdit == true)
{
dvwWorkItem.ChangeMode(DetailsViewMode.ReadOnly);
}
}
}
I apprecicate any information anyone has that might be able to solve this problem.
Jono
I never did figure my problem out. I ended up changing my program to use repeaters. They are a lot more flexible and vesitile.
B.
How did you use a repeater instead of a DetailsView, that would be strange because each now is the next field instead of a row like the GridView.
Repeaters give you full control but typing the HTML yourself but I'd like to see if I can use the features of the controls to do what I need to do before moving to the repeater. Because then I have to code those extra features that the GridView and DetailsView
have that the repeater does not.
If I work it out by myself then I'll come back here and let you know so you know what to do in the future if you decide to use a DetailsView for something.
justB
Member
25 Points
5 Posts
trouble with modechanging in detailsview
May 18, 2006 12:26 AM|LINK
My code for mode change is shown below...
protected void DetailView_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
if (e.NewMode == DetailsViewMode.Edit)
{
DetailsView1.ChangeMode(DetailsViewMode.Edit);
}
if (e.NewMode == DetailsViewMode.Insert)
{
DetailsView1.ChangeMode(DetailsViewMode.Insert);
}
if (e.NewMode == DetailsViewMode.ReadOnly)
{
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}
}
Now, when I click on edit or insert and trace, the program hits the right event, but I have to hit the button twice for the control to change mode. Even when it does change mode, regardless of which control I hit, the program will randomly decide if it is going to go into edit mode or update mode. So I might hit update and get the insert mode, or vice versa.
When in either of these modes, I have to press cancel twice to return to readonly mode.....pretty frustrating.
Thanks for the help
B.
jcasp
Star
11540 Points
2286 Posts
Re: trouble with modechanging in detailsview
May 18, 2006 03:10 AM|LINK
sophia
Contributor
2920 Points
584 Posts
Re: trouble with modechanging in detailsview
May 18, 2006 03:46 AM|LINK
If you try the following, will the issue occur?
void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Cancel")
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}
justB
Member
25 Points
5 Posts
Re: trouble with modechanging in detailsview
May 18, 2006 12:27 PM|LINK
justB
Member
25 Points
5 Posts
Re: trouble with modechanging in detailsview
May 18, 2006 12:28 PM|LINK
jcasp
Star
11540 Points
2286 Posts
Re: trouble with modechanging in detailsview
May 18, 2006 03:28 PM|LINK
VietNamMembe...
Member
5 Points
1 Post
Re: trouble with modechanging in detailsview
Jun 25, 2006 11:13 AM|LINK
After :
protected void DetailView_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
if (e.NewMode == DetailsViewMode.Edit)
{
DetailsView1.ChangeMode(DetailsViewMode.Edit);
}
if (e.NewMode == DetailsViewMode.Insert)
{
DetailsView1.ChangeMode(DetailsViewMode.Insert);
}
if (e.NewMode == DetailsViewMode.ReadOnly)
{
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}
Page_load(this,null);
}
Trying again
jonorossi
Member
180 Points
38 Posts
Re: trouble with modechanging in detailsview
Jun 27, 2006 03:59 PM|LINK
If I don't put in the ModeChanging event implementation I get an exception:
"The DetailsView 'dvwWorkItem' fired event ModeChanging which wasn't handled."
I do intend on adding other custom code into this method because certain actions need to happen when you start editing or inserting.
Here is the code I have so far:
protected void dvwWorkItem_ModeChanging(object sender, DetailsViewModeEventArgs e) { if (e.NewMode == DetailsViewMode.Edit) { dvwWorkItem.ChangeMode(DetailsViewMode.Edit); } else if (e.NewMode == DetailsViewMode.ReadOnly) { if (e.CancelingEdit == true) { dvwWorkItem.ChangeMode(DetailsViewMode.ReadOnly); } } }I apprecicate any information anyone has that might be able to solve this problem.Jono
justB
Member
25 Points
5 Posts
Re: trouble with modechanging in detailsview
Jun 27, 2006 04:26 PM|LINK
I never did figure my problem out. I ended up changing my program to use repeaters. They are a lot more flexible and vesitile.
B.
jonorossi
Member
180 Points
38 Posts
Re: trouble with modechanging in detailsview
Jun 28, 2006 12:48 AM|LINK
How did you use a repeater instead of a DetailsView, that would be strange because each now is the next field instead of a row like the GridView.
Repeaters give you full control but typing the HTML yourself but I'd like to see if I can use the features of the controls to do what I need to do before moving to the repeater. Because then I have to code those extra features that the GridView and DetailsView have that the repeater does not.
If I work it out by myself then I'll come back here and let you know so you know what to do in the future if you decide to use a DetailsView for something.
Jono