Wizard inside DetailsView bug?

C

chrisn

Hi,

(Using ASP.Net 2.0)

I have a wizard control inside a detailsview control. When I attempt
to call the InsertItem method on the DetailsView I get an error
"ObjectDataSource 'ObjectDataSource1' has no values to insert. Check
that the 'values' dictionary contains values."

I have found I can suppress the error by placing a hidden field inside
the DetailsView, but outside the Wizard control. This hidden field
must be bound to the DetailsView dataitem. The only problem with this
is that the two-way databinding is broken.

This behaviour seems very similar to that in bug FDBK27772,
http://lab.msdn.microsoft.com/Produ...edbackID=b104cbc3-8a55-4752-8c11-7e93b1d52077

I was going to submit this to Microsoft, but I thought I'd try here
first.

Thanks,
Chris Needham

Sample code below...

In app_code...

public class Animal
{
public Animal()
{
}

private int id;
public int Id
{
get { return id; }
set { id = value; }
}

private string description;
public string Description
{
get { return description; }
set { description = value; }
}
}

public class AnimalBL
{
public AnimalBL() { }

public void Insert(Animal newAnimal) { }

public Animal Select()
{
return new Animal();
}
}


In the page....


<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_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="Animal"
InsertMethod="Insert"
SelectMethod="Select"
TypeName="AnimalBL">
</asp:ObjectDataSource>

<asp:DetailsView ID="DetailsView1"
runat="server"
AutoGenerateRows="False"
DataSourceID="ObjectDataSource1"
Height="50px"
Width="125px"
DefaultMode="Insert">
<Fields>
<asp:TemplateField>
<ItemTemplate>
<asp:Wizard ID="Wizard1" runat="server"
OnFinishButtonClick="Wizard1_FinishButtonClick1">
<WizardSteps>
<asp:WizardStep ID="WizardStep1"
runat="server" Title="Step 1">
<asp:Label ID="Label1"
runat="server" Text="Description"></asp:Label>
<asp:TextBox ID="TextBox1"
runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
</form>
</body>
</html>



in the code - behind


using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Wizard1_FinishButtonClick1(object sender,
WizardNavigationEventArgs e)
{
this.DetailsView1.InsertItem(true);
}
}
 
G

Guest

Are you sure it is not a scoping thing? Does the wizard control have it's
own scope so the SQL datasource can't see the bound control textbox within
the wizard. This is much the same as you can bind a drop down list in a
template field to an SQLdatasource but you can't use the value of that drop
down as a parameter for an SQL datasource unless that SQLdatasource is within
the TemplateField.

You could get round this by simulating the databinding funtionality by using
the ItemUpdating event handler of the detailsview control and doing something
like

Wizard MyWizard = ((DetailsView)sender).FindControl("Wizard1");
TextBox MyTextBox = (TextBox)MyWizard.FindControl("TextBox1");
e.NewValues = TextBox.Text.ToString();
 
G

Guest

Perhaps it is a bug, it depends whether the wizard control is a "naming
container" however i think it is probably the scoping issue i mentioned
because that bug report is from the time when ASP.net 2.0 was still in beta
and they say that the issue is fixed. Using the two way databinding isn't
always possible for example if you have two drop down lists with the items in
the second dependent on the selectedvalue in the first there is no way to use
<%#bind("somefield")%> and you have to do it the way i sugested.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top