[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Binding Linq to SQL to Fields in Wizard Control

Posted on 2010-09-20
12
Medium Priority
?
489 Views
Last Modified: 2013-11-11
Hi,
I have used a wizard control to create a setup form that can be edited.  
I also have a linq to sql data source but cannot figure out how to bind the text boxes, drop downs etc. to the appropriate field in the data source.
How do I bind the controls?
Thanks
0
Comment
Question by:Sheritlw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33726602
I am not sure that I completely understand your question.  Can you show me the HTML for the Wizard Control?  What elements did you define in the LINQ-to-SQL data context?
0
 

Author Comment

by:Sheritlw
ID: 33727145
There seems to be no data binding option within the wizard.
I tried to bind within the load event of each wizard step, but can't get the syntax to work (I included the code in the code section).

I have tried many examples but cannot get them to work... below is my latest attempt
 'Dim q = From a In dc.Stylists() Where a.UserID = Session("UserID")

The q will not give me any fields in my datacontext.

Thanks
THE WIZARD

<asp:Wizard ID="wzdSetup" runat="server" 
     DisplaySideBar="true" CssClass="wizardsetup"
     ActiveStepIndex="0" BorderWidth="0"  > 
     
     
     <SideBarStyle CssClass="wizardsidebar"  
         VerticalAlign="Top" HorizontalAlign="Center" />
     <SideBarButtonStyle CssClass="wizardhyper" />
         
            <HeaderStyle CssClass="wizardheader" HorizontalAlign="Center" />
               
            <HeaderTemplate>

            <b><%=wzdSetup.ActiveStep.Title%></b>

            <br />

            </HeaderTemplate>
            
            <StartNavigationTemplate>


            <asp:Button ID="NextButton" runat="server"  Text="NEXT" cssClass="wizardnextback" CommandName="MoveNext" />
               
            </StartNavigationTemplate>

            <StepNavigationTemplate >

            <asp:Button ID="PreviousButton" runat="server" Text="PREVIOUS" CommandName="MovePrevious" />

            <asp:Button ID="StartNextButton" cssClass="wizardnextback" runat="server" Text="NEXT" CommandName="MoveNext" />           
               
            </StepNavigationTemplate>

            <FinishNavigationTemplate>

            

            <asp:Button ID="PreviousButton" runat="server" Text="PREVIOUS" CommandName="MovePrevious" />

            <asp:Button ID="FinishButton" runat="server" Text="FINISH" cssClass="wizardnextback" CommandName="MoveComplete" />      

            </FinishNavigationTemplate>

            <WizardSteps>

                <asp:WizardStep ID="wzdContactInfo" runat="server" Title="Contact Info.">
               <table class="wizardtable">
               
                    <colgroup>
                         <col width="35%" />
                         <col width="75%" />
                     </colgroup>     
                         
                         <tr>
                              <th class="logintext" colspan="2">
                                   Enter Contact Information</th>
                         </tr>
                         <tr>
                              <td colspan="2">
                                   &nbsp;
                              </td>
                         </tr>
                         <tr>
                              <td>
                                   First Name:</td>
                              <td>
                                
                                   <asp:TextBox ID="txtFirstName" runat="server" CssClass="wizardboxes"
                                        MaxLength="50" ></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                        ControlToValidate="FirstName" Display="Dynamic" 
                                        ErrorMessage="First name is required."></asp:RequiredFieldValidator></td></tr><tr>
                              <td>
                                   Last Name:</td><td>
                                   <asp:TextBox ID="txtLastName" runat="server" CssClass="wizardboxes" 
                                        MaxLength="50"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                        ControlToValidate="LastName" Display="Dynamic" 
                                        ErrorMessage="Last name is required."></asp:RequiredFieldValidator></td></tr><tr>
                              <td>
                                   Professional Category:</td><td>
                                   <asp:DropDownList ID="ddProfCategory" runat="server" CssClass="wizardboxes" 
                                        Width="72%">
                                        <asp:ListItem>What is your mother&#39;s maiden name?</asp:ListItem><asp:ListItem>In what city were you born?</asp:ListItem><asp:ListItem>What is your favorite sport?</asp:ListItem><asp:ListItem>How much wood could a woodchuck chuck if a woodchuck could chuck wood?</asp:ListItem></asp:DropDownList></td></tr><tr>
                              <td>
                                   Salon Name:</td><td>
                                   <asp:TextBox ID="txtSalonName" runat="server" Columns="10" 
                                        CssClass="wizardboxes" MaxLength="10"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                                        ControlToValidate="SalonName" Display="Dynamic" 
                                        ErrorMessage="Salon name is required in order for clients to search."></asp:RequiredFieldValidator></td></tr><tr>
                              <td>
                                   Address:</td><td>
                                   <asp:TextBox ID="txtSalonAdd" runat="server" CssClass="wizardboxes" 
                                        MaxLength="50"></asp:TextBox></td></tr><tr>
                              <td>
                                   City/Province:</td><td>
                                   <asp:TextBox ID="txtSalonCity" runat="server" CssClass="wizardboxes" 
                                        MaxLength="50"></asp:TextBox></td></tr><tr>
                              <td>
                                   State/Postal:</td><td>
                                   <asp:DropDownList ID="ddStateID" runat="server" CssClass="wizardboxes" 
                                        Width="45%">
                                   </asp:DropDownList>
                                   <asp:TextBox ID="SalonZip" runat="server" MaxLength="10" Width="23%"></asp:TextBox></td></tr><tr>
                              <td>
                                   Email:</td><td>
                                   <asp:TextBox ID="txtStylistEmail" runat="server" CssClass="wizardboxes"></asp:TextBox><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                                        ControlToValidate="txtStylistEmail" Display="Dynamic" 
                                        ErrorMessage="You must enter a valid email address" 
                                        ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td></tr><tr>
                              <td>
                                   Domain Name:</td><td>
                                   <asp:TextBox ID="txtDomain" runat="server" CssClass="wizardboxes" 
                                        MaxLength="20"></asp:TextBox><asp:Label ID="lblDomain" runat="server" Text="www.smsmain.com/domainname"></asp:Label></td></tr><tr>
                              <td colspan="2">
                                   &nbsp;
                              </td>
                         </tr>
                   
              
              
          </table>
          
          <table class="wizardtable">
               
                    <colgroup>
                         <col width="25%" />
                         <col width="25%" />
                         <col width="25%" />
                         <col width="25%" />
                    </colgroup>
                      
                         <tr>
                              <td>
                                   Primary Phone</td><td>
                                   Work Phone</td><td>
                                   Mobile Phone</td><td>
                                   Home Phone</td></tr><tr>
                              <td>
                                   <asp:TextBox ID="txtStylistPrimePhone" runat="server" MaxLength="10" 
                                        Width="80%"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                                        ControlToValidate="txtStylistPrimePhone" Display="Dynamic" 
                                        ErrorMessage="Primary phone number is required."></asp:RequiredFieldValidator></td><td>
                                   <asp:TextBox ID="txtStylistWkPhone" runat="server" MaxLength="10" Width="80%"></asp:TextBox></td><td>
                                   <asp:TextBox ID="txtStylistMobPhone" runat="server" MaxLength="10" Width="80%"></asp:TextBox></td><td>
                                   <asp:TextBox ID="txtStylistHomePhone" runat="server" MaxLength="10" Width="80%"></asp:TextBox></td></tr><tr>
                              <td colspan="4">
                                   &nbsp;
                              </td>
                         </tr>
                         <tr>
                              <td colspan="4">
                                   <asp:CheckBox ID="chkStylistSearchable" runat="server" Checked="True" 
                                        Text="Allow your name to be found by potentials clients/clients?" />
                              </td>
                         </tr>
                         <tr>
                              <td colspan="4">
                                   <asp:CheckBox ID="chkAllowBioView" runat="server" Checked="True" 
                                        Text="Allow potentials clients/clients to view your Bio?" />
                              </td>
                         </tr>
                         <tr>
                              <td colspan="4">
                                   <asp:CheckBox ID="chkAllowPort" runat="server" Checked="True" 
                                        Text="Allow potentials clients/clients to view your portfolio?" />
                              </td>
                         </tr>
                         <tr>
                              <td colspan="4">
                                   &nbsp;
                              </td>
                         </tr>
                         <tr>
                              <td align="center" colspan="4">
                                   <asp:Button ID="buttContactCancel" runat="server" CssClass="wizardbutton" 
                                        Text="Cancel" />
                                   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                   <asp:Button ID="buttContactSave" runat="server" CssClass="wizardbutton" 
                                        OnClick="buttContactSave_Click" Text="Save" />
                              </td>
                         </tr>
                         <tr>
                              <td colspan="4">
                                   &nbsp;
                                   
                                   <asp:LinqDataSource ID="LinqStylistContact" runat="server" 
                                        ContextTypeName="SalonClassesDataContext" 
                                        Select="new (StylistID, UserID, ProfCategoryID, SalonName, SalonAdd, SalonCity, StateID, SalonZip, FullName, FName, LName, PrimaryPhone, WkPhone, MobPhone, HmPhone, EmailAdd, Searchable, AllowBioView, AllowPortView, DomainName)" 
                                        TableName="Stylists" Where="UserID == @UserID">
                                        <WhereParameters>
                                             <asp:SessionParameter DbType="Guid" Name="UserID" SessionField="UserID" />
                                        </WhereParameters>
                                   </asp:LinqDataSource>
                                   
                              </td>
                         </tr>
                    
             
               </table>                
           </asp:WizardStep>

THE STEP LOAD EVENT

Protected Sub wzdContactInfo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles wzdContactInfo.Load

          Dim dc As New SalonClassesDataContext()
          If Not Page.IsPostBack Then
               If User.Identity.IsAuthenticated Then
                    Dim u As MembershipUser = Membership.GetUser(User.Identity.Name.ToString())
                    Session("UserID") = u.ProviderUserKey.ToString()
               End If
          End If

          'Dim q = From a In dc.Stylists() Where a.UserID = Session("UserID")


          'Me.txtAdd1.Text = 




     End Sub

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33727758
There isn't any data-binding for the Wizard control, that I know of, but you should be able to get references to the underlying controls with FindControl, and then set the values, or fill a DropDownList, etc.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:Sheritlw
ID: 33727928
I have figured out how assign information to the fields and I can manage it in code behind.
My problem now is the linq to sql syntax I am using to retrieve the field values from the db.

Dim dc As New SalonClassesDataContext()

Dim q = From a In dc.Stylists() Where a.UserID = Session("UserID")

From what I have read, I should be able to get the values from the db from the line above.

But q does not return the fieldname.

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33727943
I don't see any Select condition, like this (guess):

Dim q = From a In dc.Stylists() Where a.UserID = Session("UserID") Select a.FieldName
0
 

Author Comment

by:Sheritlw
ID: 33727962
Oh,  so it in not selecting the table?  I need to create a select statement?
What if I wanted to just get the table?
Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33728143
If you want all the properties, then you can do something like this:

Dim q = From a In dc.Stylists() Where a.UserID = Session("UserID") Select a
0
 

Author Comment

by:Sheritlw
ID: 33728275
That's cool... Loving Linq to sql

But how do I assign the values to the text boxes?

Example..

Dim q = From a In dc.Stylists() Where a.UserID = Session("UserID") Select a
       
  Me.txtAdd1.Text = q??????

Thanks
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 33728437
If you are assigning to TextBox controls, then you need a single record.  You can use FirstOrDefault or SingleOrDefault to get a single record.

Dim q = (From a In dc.Stylists() Where a.UserID = Session("UserID") Select a).FirstOrDefault()

If q Is Nothing Then
    Throw New NullReferenceException("Stylist not found for user ID  " & Session("UserID"))
End If

Me.txtAdd1.Text = q.Address1
0
 

Author Comment

by:Sheritlw
ID: 33728525
That was it.  I have read a lot of stuff about LInq to SQL, but never read anything on firstordefault.
Is there a good site that has examples of linq to sql statements?

Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33729128
For VB.NET, this is the site that I use:

101 Visual Basic LINQ Samples
http://msdn.microsoft.com/en-us/vbasic/bb688088.aspx
0
 

Author Comment

by:Sheritlw
ID: 33729140
Great, Thank you so much for your help.
You have helped me a lot over the passed couple of years.

Thanks again
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question