Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Detailsview with objectdatasource

Reply
Thread Tools

Detailsview with objectdatasource

 
 
Paul S
Guest
Posts: n/a
 
      04-01-2010
I'm using a detailsview with an objectdatasource. When I click Update to
save my edited record ItemUpdating gets called but e.NewValues.Count = 0.

What am I doing wrong?

The design is a dropdown ddlEvent where a date is selected. With taht as a
key the event to be edited is selected in the DetailsView


protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
try
{
MatchCollection matches = new MatchCollection();
matches.FillWithEventsAfter(new DateTime(2009, 1, 1), 10);

this.ddlEvent.DataValueField = "MatchId";
this.ddlEvent.DataTextField = "DateOfEvent";
this.ddlEvent.DataSource = matches;
this.ddlEvent.DataBind();

this.BindDetailsView();

}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}

/// <summary>
/// New date has been selected so refresh view
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlEvent_SelectedIndexChanged(object sender,
EventArgs e)
{
//Response.Write(this.ddlEvent.SelectedValue.ToStrin g());
this.BindDetailsView();
}

private void BindDetailsView()
{
MatchCollection matches = new MatchCollection();
matches.Fill(int.Parse(this.ddlEvent.SelectedValue ));

this.dvEvent.DataSource = matches;
this.dvEvent.DataBind();
this.dvEvent.DefaultMode = DetailsViewMode.ReadOnly;
}

protected void dvEvent_ModeChanged(object sender, EventArgs e)
{
}

protected void dvEvent_ModeChanging(object sender,
DetailsViewModeEventArgs e)
{
this.dvEvent.ChangeMode(e.NewMode);
this.BindDetailsView();
}

protected void dvEvent_ItemCommand(object sender,
DetailsViewCommandEventArgs e)
{
if (e.CommandName.Equals("edit",
StringComparison.InvariantCultureIgnoreCase))
{
}
if (e.CommandName.Equals("Cancel",
StringComparison.InvariantCultureIgnoreCase))
{
;
}
if (e.CommandName.Equals("New",
StringComparison.InvariantCultureIgnoreCase))
;

if (e.CommandName.Equals("update",
StringComparison.InvariantCultureIgnoreCase))
{
this.dvEvent.UpdateItem(true);
}
}

protected void dvEvent_ItemUpdating(object sender,
DetailsViewUpdateEventArgs e)
{
MatchCollection matches = new MatchCollection();
matches.Fill(int.Parse(this.ddlEvent.SelectedValue ));
if (matches.Count < 1)
return;

MatchInfo mi = matches[0];
mi.Description = e.NewValues["Description"].ToString();
mi.CourseId = (int)e.NewValues["CourseId"];
// etc
try
{
matches.Update();
this.dvEvent.ChangeMode(DetailsViewMode.ReadOnly);
}
catch (Exception)
{
}
// error handling
}



Thanks
Paul S
 
Reply With Quote
 
 
 
 
Steven Cheng
Guest
Posts: n/a
 
      06-23-2010
Hi Paul,

From your description, the DetailsView.ItemUpdating event doesn't contain
the proper values(in the NewValues collection) when performing updating,
correct?

I'm wondering whether it is a datasource or control specific issue. Have
you tried directly using a SqlDataSource control for the DetailsView
connection or directly connect the DetailsView to datasource control
without filtering from the dropdownlist to see whether it makes any
difference?

I've tried a simple SqlDataSource case with the ItemUpdating event below
which shows all the parameters in both OldValues and NewValues collection:

>>>>>>>>>>>>>>>>>>>>>>>>>>>

protected void DetailsView2_ItemUpdating(object sender,
DetailsViewUpdateEventArgs e)
{
Response.Write("<br/>Old values:");
foreach (var oldp in e.OldValues.Keys)
{
Response.Write("<br/>" + oldp);
}

Response.Write("<br/>New values:");
foreach (var newp in e.NewValues.Keys)
{
Response.Write("<br/>" + newp);
}
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead




--------------------
>Thread-Topic: Detailsview with objectdatasource
>From: =?Utf-8?B?UGF1bCBT?= <(E-Mail Removed)>
>Subject: Detailsview with objectdatasource
>Date: Thu, 1 Apr 2010 08:47:01 -0700
>
>I'm using a detailsview with an objectdatasource. When I click Update to
>save my edited record ItemUpdating gets called but e.NewValues.Count = 0.
>
>What am I doing wrong?
>
>The design is a dropdown ddlEvent where a date is selected. With taht as a
>key the event to be edited is selected in the DetailsView
>
>
>protected void Page_Load(object sender, EventArgs e)
>{
>if (!this.IsPostBack)
>{
>try
>{
>MatchCollection matches = new MatchCollection();
>matches.FillWithEventsAfter(new DateTime(2009, 1, 1), 10);
>
>this.ddlEvent.DataValueField = "MatchId";
>this.ddlEvent.DataTextField = "DateOfEvent";
>this.ddlEvent.DataSource = matches;
>this.ddlEvent.DataBind();
>
>this.BindDetailsView();
>
>}
>catch (Exception ex)
>{
>Response.Write(ex.ToString());
>}
>}
>}
>
>/// <summary>
>/// New date has been selected so refresh view
>/// </summary>
>/// <param name="sender"></param>
>/// <param name="e"></param>
>protected void ddlEvent_SelectedIndexChanged(object sender,
>EventArgs e)
>{
>//Response.Write(this.ddlEvent.SelectedValue.ToStrin g());
>this.BindDetailsView();
>}
>
>private void BindDetailsView()
>{
>MatchCollection matches = new MatchCollection();
>matches.Fill(int.Parse(this.ddlEvent.SelectedValu e));
>
>this.dvEvent.DataSource = matches;
>this.dvEvent.DataBind();
>this.dvEvent.DefaultMode = DetailsViewMode.ReadOnly;
>}
>
>protected void dvEvent_ModeChanged(object sender, EventArgs e)
>{
>}
>
>protected void dvEvent_ModeChanging(object sender,
>DetailsViewModeEventArgs e)
>{
>this.dvEvent.ChangeMode(e.NewMode);
>this.BindDetailsView();
>}
>
>protected void dvEvent_ItemCommand(object sender,
>DetailsViewCommandEventArgs e)
>{
>if (e.CommandName.Equals("edit",
>StringComparison.InvariantCultureIgnoreCase))
>{
>}
>if (e.CommandName.Equals("Cancel",
>StringComparison.InvariantCultureIgnoreCase))
>{
>;
>}
>if (e.CommandName.Equals("New",
>StringComparison.InvariantCultureIgnoreCase))
>;
>
>if (e.CommandName.Equals("update",
>StringComparison.InvariantCultureIgnoreCase))
>{
>this.dvEvent.UpdateItem(true);
>}
>}
>
>protected void dvEvent_ItemUpdating(object sender,
>DetailsViewUpdateEventArgs e)
>{
>MatchCollection matches = new MatchCollection();
>matches.Fill(int.Parse(this.ddlEvent.SelectedValu e));
>if (matches.Count < 1)
>return;
>
>MatchInfo mi = matches[0];
>mi.Description = e.NewValues["Description"].ToString();
>mi.CourseId = (int)e.NewValues["CourseId"];
>// etc
>try
>{
>matches.Update();
>this.dvEvent.ChangeMode(DetailsViewMode.ReadOnly) ;
>}
>catch (Exception)
>{
>}
>// error handling
>}
>
>
>
>Thanks
>Paul S
>


 
Reply With Quote
 
 
 
 
Paul S
Guest
Posts: n/a
 
      06-25-2010
Hi Steven
I haven't tried the SqlDataSource but I'll do that

Thanks
Paul S

""Steven Cheng"" wrote:

> Hi Paul,
>
> From your description, the DetailsView.ItemUpdating event doesn't contain
> the proper values(in the NewValues collection) when performing updating,
> correct?
>
> I'm wondering whether it is a datasource or control specific issue. Have
> you tried directly using a SqlDataSource control for the DetailsView
> connection or directly connect the DetailsView to datasource control
> without filtering from the dropdownlist to see whether it makes any
> difference?
>
> I've tried a simple SqlDataSource case with the ItemUpdating event below
> which shows all the parameters in both OldValues and NewValues collection:
>
> >>>>>>>>>>>>>>>>>>>>>>>>>>>

> protected void DetailsView2_ItemUpdating(object sender,
> DetailsViewUpdateEventArgs e)
> {
> Response.Write("<br/>Old values:");
> foreach (var oldp in e.OldValues.Keys)
> {
> Response.Write("<br/>" + oldp);
> }
>
> Response.Write("<br/>New values:");
> foreach (var newp in e.NewValues.Keys)
> {
> Response.Write("<br/>" + newp);
> }
> }
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
>
>
> --------------------
> >Thread-Topic: Detailsview with objectdatasource
> >From: =?Utf-8?B?UGF1bCBT?= <(E-Mail Removed)>
> >Subject: Detailsview with objectdatasource
> >Date: Thu, 1 Apr 2010 08:47:01 -0700
> >
> >I'm using a detailsview with an objectdatasource. When I click Update to
> >save my edited record ItemUpdating gets called but e.NewValues.Count = 0.
> >
> >What am I doing wrong?
> >
> >The design is a dropdown ddlEvent where a date is selected. With taht as a
> >key the event to be edited is selected in the DetailsView
> >
> >
> >protected void Page_Load(object sender, EventArgs e)
> >{
> >if (!this.IsPostBack)
> >{
> >try
> >{
> >MatchCollection matches = new MatchCollection();
> >matches.FillWithEventsAfter(new DateTime(2009, 1, 1), 10);
> >
> >this.ddlEvent.DataValueField = "MatchId";
> >this.ddlEvent.DataTextField = "DateOfEvent";
> >this.ddlEvent.DataSource = matches;
> >this.ddlEvent.DataBind();
> >
> >this.BindDetailsView();
> >
> >}
> >catch (Exception ex)
> >{
> >Response.Write(ex.ToString());
> >}
> >}
> >}
> >
> >/// <summary>
> >/// New date has been selected so refresh view
> >/// </summary>
> >/// <param name="sender"></param>
> >/// <param name="e"></param>
> >protected void ddlEvent_SelectedIndexChanged(object sender,
> >EventArgs e)
> >{
> >//Response.Write(this.ddlEvent.SelectedValue.ToStrin g());
> >this.BindDetailsView();
> >}
> >
> >private void BindDetailsView()
> >{
> >MatchCollection matches = new MatchCollection();
> >matches.Fill(int.Parse(this.ddlEvent.SelectedValu e));
> >
> >this.dvEvent.DataSource = matches;
> >this.dvEvent.DataBind();
> >this.dvEvent.DefaultMode = DetailsViewMode.ReadOnly;
> >}
> >
> >protected void dvEvent_ModeChanged(object sender, EventArgs e)
> >{
> >}
> >
> >protected void dvEvent_ModeChanging(object sender,
> >DetailsViewModeEventArgs e)
> >{
> >this.dvEvent.ChangeMode(e.NewMode);
> >this.BindDetailsView();
> >}
> >
> >protected void dvEvent_ItemCommand(object sender,
> >DetailsViewCommandEventArgs e)
> >{
> >if (e.CommandName.Equals("edit",
> >StringComparison.InvariantCultureIgnoreCase))
> >{
> >}
> >if (e.CommandName.Equals("Cancel",
> >StringComparison.InvariantCultureIgnoreCase))
> >{
> >;
> >}
> >if (e.CommandName.Equals("New",
> >StringComparison.InvariantCultureIgnoreCase))
> >;
> >
> >if (e.CommandName.Equals("update",
> >StringComparison.InvariantCultureIgnoreCase))
> >{
> >this.dvEvent.UpdateItem(true);
> >}
> >}
> >
> >protected void dvEvent_ItemUpdating(object sender,
> >DetailsViewUpdateEventArgs e)
> >{
> >MatchCollection matches = new MatchCollection();
> >matches.Fill(int.Parse(this.ddlEvent.SelectedValu e));
> >if (matches.Count < 1)
> >return;
> >
> >MatchInfo mi = matches[0];
> >mi.Description = e.NewValues["Description"].ToString();
> >mi.CourseId = (int)e.NewValues["CourseId"];
> >// etc
> >try
> >{
> >matches.Update();
> >this.dvEvent.ChangeMode(DetailsViewMode.ReadOnly) ;
> >}
> >catch (Exception)
> >{
> >}
> >// error handling
> >}
> >
> >
> >
> >Thanks
> >Paul S
> >

>
> .
>

 
Reply With Quote
 
Steven Cheng
Guest
Posts: n/a
 
      06-28-2010
Thanks for your reply Paul,

Yes, by checking different controls can help verify whether the problem is
specific to the objectdatasource or the data access class it uses
internally.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
--------------------
>From: =?Utf-8?B?UGF1bCBT?= <(E-Mail Removed)>
>References: <(E-Mail Removed)>

<(E-Mail Removed)>
>Subject: RE: Detailsview with objectdatasource
>Date: Fri, 25 Jun 2010 01:41:54 -0700


>
>Hi Steven
>I haven't tried the SqlDataSource but I'll do that
>
>Thanks
>Paul S
>
>""Steven Cheng"" wrote:
>
>> Hi Paul,
>>
>> From your description, the DetailsView.ItemUpdating event doesn't

contain
>> the proper values(in the NewValues collection) when performing updating,
>> correct?
>>
>> I'm wondering whether it is a datasource or control specific issue. Have
>> you tried directly using a SqlDataSource control for the DetailsView
>> connection or directly connect the DetailsView to datasource control
>> without filtering from the dropdownlist to see whether it makes any
>> difference?
>>
>> I've tried a simple SqlDataSource case with the ItemUpdating event below
>> which shows all the parameters in both OldValues and NewValues

collection:
>>
>> >>>>>>>>>>>>>>>>>>>>>>>>>>>

>> protected void DetailsView2_ItemUpdating(object sender,
>> DetailsViewUpdateEventArgs e)
>> {
>> Response.Write("<br/>Old values:");
>> foreach (var oldp in e.OldValues.Keys)
>> {
>> Response.Write("<br/>" + oldp);
>> }
>>
>> Response.Write("<br/>New values:");
>> foreach (var newp in e.NewValues.Keys)
>> {
>> Response.Write("<br/>" + newp);
>> }
>> }
>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>
>> Sincerely,
>>
>> Steven Cheng
>>
>> Microsoft MSDN Online Support Lead
>>
>>
>>
>>
>> --------------------
>> >Thread-Topic: Detailsview with objectdatasource
>> >From: =?Utf-8?B?UGF1bCBT?= <(E-Mail Removed)>
>> >Subject: Detailsview with objectdatasource
>> >Date: Thu, 1 Apr 2010 08:47:01 -0700
>> >
>> >I'm using a detailsview with an objectdatasource. When I click Update to
>> >save my edited record ItemUpdating gets called but e.NewValues.Count =

0.
>> >
>> >What am I doing wrong?
>> >
>> >The design is a dropdown ddlEvent where a date is selected. With taht

as a
>> >key the event to be edited is selected in the DetailsView
>> >
>> >
>> >protected void Page_Load(object sender, EventArgs e)
>> >{
>> >if (!this.IsPostBack)
>> >{
>> >try
>> >{
>> >MatchCollection matches = new MatchCollection();
>> >matches.FillWithEventsAfter(new DateTime(2009, 1, 1), 10);
>> >
>> >this.ddlEvent.DataValueField = "MatchId";
>> >this.ddlEvent.DataTextField = "DateOfEvent";
>> >this.ddlEvent.DataSource = matches;
>> >this.ddlEvent.DataBind();
>> >
>> >this.BindDetailsView();
>> >
>> >}
>> >catch (Exception ex)
>> >{
>> >Response.Write(ex.ToString());
>> >}
>> >}
>> >}
>> >
>> >/// <summary>
>> >/// New date has been selected so refresh view
>> >/// </summary>
>> >/// <param name="sender"></param>
>> >/// <param name="e"></param>
>> >protected void ddlEvent_SelectedIndexChanged(object sender,
>> >EventArgs e)
>> >{
>> >//Response.Write(this.ddlEvent.SelectedValue.ToStrin g());
>> >this.BindDetailsView();
>> >}
>> >
>> >private void BindDetailsView()
>> >{
>> >MatchCollection matches = new MatchCollection();
>> >matches.Fill(int.Parse(this.ddlEvent.SelectedValu e));
>> >
>> >this.dvEvent.DataSource = matches;
>> >this.dvEvent.DataBind();
>> >this.dvEvent.DefaultMode = DetailsViewMode.ReadOnly;
>> >}
>> >
>> >protected void dvEvent_ModeChanged(object sender, EventArgs e)
>> >{
>> >}
>> >
>> >protected void dvEvent_ModeChanging(object sender,
>> >DetailsViewModeEventArgs e)
>> >{
>> >this.dvEvent.ChangeMode(e.NewMode);
>> >this.BindDetailsView();
>> >}
>> >
>> >protected void dvEvent_ItemCommand(object sender,
>> >DetailsViewCommandEventArgs e)
>> >{
>> >if (e.CommandName.Equals("edit",
>> >StringComparison.InvariantCultureIgnoreCase))
>> >{
>> >}
>> >if (e.CommandName.Equals("Cancel",
>> >StringComparison.InvariantCultureIgnoreCase))
>> >{
>> >;
>> >}
>> >if (e.CommandName.Equals("New",
>> >StringComparison.InvariantCultureIgnoreCase))
>> >;
>> >
>> >if (e.CommandName.Equals("update",
>> >StringComparison.InvariantCultureIgnoreCase))
>> >{
>> >this.dvEvent.UpdateItem(true);
>> >}
>> >}
>> >
>> >protected void dvEvent_ItemUpdating(object sender,
>> >DetailsViewUpdateEventArgs e)
>> >{
>> >MatchCollection matches = new MatchCollection();
>> >matches.Fill(int.Parse(this.ddlEvent.SelectedValu e));
>> >if (matches.Count < 1)
>> >return;
>> >
>> >MatchInfo mi = matches[0];
>> >mi.Description = e.NewValues["Description"].ToString();
>> >mi.CourseId = (int)e.NewValues["CourseId"];
>> >// etc
>> >try
>> >{
>> >matches.Update();
>> >this.dvEvent.ChangeMode(DetailsViewMode.ReadOnly) ;
>> >}
>> >catch (Exception)
>> >{
>> >}
>> >// error handling
>> >}
>> >
>> >
>> >
>> >Thanks
>> >Paul S
>> >

>>
>> .
>>

>


 
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
Couple of questions about DetailsView and ObjectDataSource controls J055 ASP .Net 1 04-05-2006 01:53 PM
DetailsView ObjectDataSource and strongly typed dataset Spotnick ASP .Net 0 01-21-2006 07:56 PM
DetailsView: InsertMethod not function [ObjectDataSource] =?Utf-8?B?Q1dXb25n?= ASP .Net 3 01-05-2006 09:32 AM
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
DetailsView and ObjectDataSource - how to get updated object =?Utf-8?B?SmltIEhhbW1vbmQ=?= ASP .Net 12 10-17-2005 11:27 PM



Advertisments