If you have tried to use the Wizard ASP.NET web control for more than just inserting data, you were probably shocked to find out that it's not bindable. Why shouldn't we be able to use the Wizard the same way we use FormView? If we use a Wizard to insert data, wouldn't we want to view that data and edit it the same way? How could Microsoft have overlooked this? Well, who knows?
The best workaround I could come up with is not as simple as I'd like (after all the whole purpose of binding controls to an ObjectDataSource is to simplify matters); but it does work to a degree:
- Create a User Control
- Add the Wizard to the User Control
- Define properties for the User Control to expose the web controls that need to be bound
- Create an ASPX page and add a Formview and an ObjectDataSource
- Drag the User Control (from step a above) into the FormView's EditItemTemplate
- Bind the properties of the User Control to the item data (e.g. Name='Bind("name")')
You should also set the FormView's InsertItemTemplate to the EditItemTemplate in the page load event (to avoid redundancy):
FormView1.InsertItemTemplate = FormView1.EditItemTemplate
Sample ASPX (ASP.NET Page):
<asp:FormView ID="FormView1" Width="100%" runat="server" DataSourceID="ObjectDataSource1" DefaultMode="Insert">
<EditItemTemplate>
<uc1:UcWizard ID="UcWizard1" runat="server"
Title='<%#Bind("Name")%>'
Details='<%#Bind("Description")%>'
Category='<%#Bind("CategoryId")%>'
AddressLine1='<%# Bind("AddressLine1")%>'
AddressLine2='<%#Bind("AddressLine2")%>'
City='<%#Bind("City")%>'
State='<%#Bind("State")%>'
ZipCode='<%#Bind("ZipCode")%>'
/>
</EditItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetAsset" InsertMethod="InsertAsset" TypeName="MyApp.DataAccess.Db_Assets"
UpdateMethod="UpdateAsset">
</asp:ObjectDataSource>
Sample ASCX (User Control):
<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0"
BackColor="#F7F6F3"
Font-Names="Verdana" CellPadding="10" Height="100%">
<StepStyle BorderWidth="0px" ForeColor="#5D7B9D" />
<NavigationStyle HorizontalAlign="Left" />
<WizardSteps>
<asp:WizardStep runat="server" Title="Enter Location" ID="step_location">
<table>
<tr>
<td></td>
<td>Business Name:</td>
<td><asp:TextBox ID="tbBusiness" runat="server" Width="182px"></asp:TextBox></td>
</tr>
<tr>
<td> </td>
<td>Address Line 1:</td>
<td><asp:TextBox ID="tbAddress1" runat="server" Width="310px"></asp:TextBox></td>
</tr>
<tr>
|