Solved

Pull Multiple Values from VB datasource

Posted on 2009-05-05
33
249 Views
Last Modified: 2012-05-06
I have the attached form I am creating in Visual Studio.  I am stuck at the Directory Advertising and Show Daily Advertising sections where I need to grab display the size and also get the price for that selection to calculate in the rate box.

See attached
FabtechSales.pdf
0
Comment
Question by:Albee_J
  • 18
  • 15
33 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Can you show us some code?
0
 

Author Comment

by:Albee_J
Comment Utility
I have only begun coding the top section, I have started coding the Product Choices as I am trying to figure out the best way to handle the fact that a size is going to be pulled into a drop down list that only allows for 2 values to be extracted. The display and the Value.  The display will show the Size Name, the Value will be the Size ID, but I somehow then need to get the SizePrice based on the selected value as well.  

I will pull some fields into my project for the first product and postback here.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
There are two options for doing that. Either populate a DataTable in memory and then use filtering to find the size price. Or query the database for size price given the selected size id.
0
 

Author Comment

by:Albee_J
Comment Utility
I am unsure of the syntax on how to do that.

Below is the code I currently have:

Partial Class Default2
    Inherits System.Web.UI.Page
    Sub Page_Load()
        Dim value As String
        If ckDirAd.Checked Then
            value = "1"
        Else
            value = ""
        End If

    End Sub

    Sub CalcMultiple()
        Const Multiple As Double = 500

        If ckMultiple.Checked = True Then txtMultipleRate.Text = FormatCurrency(Multiple)

    End Sub
    Sub CalcDirectory()
        If ckDirAd.Checked = True And ckDirSpecial.Checked = False Then
            'I forced a value in here, this really should be the Price of the Size selected the ddlDirSize
            txtDirRate.Text = 500
        ElseIf ckDirAd.Checked = True And ckDirSpecial.Checked = True Then
            txtDirRate.Text = 500 * 1.12
        ElseIf ckDirAd.Checked = False And ckDirSpecial.Checked = False Then
            txtDirRate.Text = ""
        End If



    End Sub

    Protected Sub txtMultiple_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckMultiple.CheckedChanged

        If ckMultiple.Checked = True Then
            lblSecondary.Text = "Secondary Company Name:"
            lblSecondary.ToolTip = "Enter in Secondary company name as it is to be shown in directory/web"
            lblMultipleIn.Visible = True
            ckMultipleIn.Visible = True
            lblMultipleRate.Visible = True
            txtMultipleRate.Visible = True
            CalcMultiple()

        Else
            lblSecondary.Text = "Other Advertiser:"
            lblSecondary.ToolTip = "Not Exhibiting or sharing a booth, list company name"
            lblMultipleIn.Visible = False
            ckMultipleIn.Visible = False
            lblMultipleRate.Visible = False
            txtMultipleRate.Visible = False
     
        End If
    End Sub

    Protected Sub ckDirAd_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirAd.CheckedChanged
        CalcDirectory()
    End Sub

    Protected Sub ckDirSpecial_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirSpecial.CheckedChanged
        CalcDirectory()
    End Sub
End Class
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Try this code
'Page Load:

'Assuming you have populated a datatable already
 

cbxSizes.DataSource = DTable

cbxSizes.DisplayMember = "SizeName"

cbxSizes.ValueMember = "SizeID"
 
 

'combobox selectedindex changed or somewhere else.
 

Dim ID as integer = cbxSizes.SelectedValue

dTable.DefaultView.RowFilter = "SizeID=" & ID

if dTable.DefaultView.Count = 1 Then

   txtPrice.Text = dTable.DefaultView.item(0).item("SizePrice")

End If

Open in new window

0
 

Author Comment

by:Albee_J
Comment Utility
Ah beautiful! I will implement, test and advise
0
 

Author Comment

by:Albee_J
Comment Utility
I am getting errors here:

  ddlDirSize.DisplayMember = "OptionType"
        ddlDirSize.ValueMember = "OptionID"  

stating that  Error      1      'DisplayMember' is not a member of 'System.Web.UI.WebControls.DropDownList'.      C:\Users\jalbee\Documents\Visual Studio 2005\WebSites\FabtechSales\InsertOrders.aspx.vb      14      9      C:\...\FabtechSales\


and errors here:

    ProductSizes.DefaultView.RowFilter = "SizeID=" & ID
        If ProductSizes.DefaultView.Count = 1 Then
            txtDirRate.Text = ProductSizes.DefaultView.item(0).item("SizePrice")

stating that 'DefaultView' is not a member of 'System.Web.UI.WebControls.SqlDataSource'.      C:\Users\jalbee\Documents\Visual Studio 2005\WebSites\FabtechSales\InsertOrders.aspx.vb      23      31      C:\...\FabtechSales\

     ddlDirSize.DataSource = ProductSizes

        ddlDirSize.DisplayMember = "OptionType"

        ddlDirSize.ValueMember = "OptionID"
 
 

        'combobox selectedindex changed or somewhere else.
 

        Dim ID As Integer = ddlDirSize.SelectedValue

        ProductSizes.DefaultView.RowFilter = "SizeID=" & ID

        If ProductSizes.DefaultView.Count = 1 Then

            txtDirRate.Text = ProductSizes.DefaultView.item(0).item("SizePrice")

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Ah ASP.NET. Change

        ddlDirSize.DisplayMember = "OptionType"
        ddlDirSize.ValueMember = "OptionID"

To

        ddlDirSize.DataTextField = "OptionType"
        ddlDirSize.DataValueField = "OptionID"


I said you need to use a DataTable not a SQLDataSource. Do this to create and populate a datatable.

Dim dTable as New DataTable
dim dbadp as new SQLDataAdapter("Select * from tablename", connectionstring)
dbadp.fill(dTable)
dbadp.dispose
Session("dTable")=dTable
'then the ddl code here

'SelectedIndex changed
dim dTable as DataTable  = Session("dTable")
If Not IsNothing(dTable) Then
   'the defaultview code here.
End If
0
 

Author Comment

by:Albee_J
Comment Utility
The only error I a getting is here:

     'SelectedIndex changed
        Dim dTable As Data.DataTable = Session("dTable")

Error      1      Local variable 'dTable' is already declared in the current block.      C:\Users\jalbee\Documents\Visual Studio 2005\WebSites\FabtechSales\InsertOrders.aspx.vb      26      13      C:\...\FabtechSales\


Here is the full code:


        'Create data table
        Dim ConnectionString As String
        ConnectionString = "Server=FMASQL;database=HidingInformation"
        Dim dTable As New Data.DataTable
        Dim dbadp As New Data.SqlClient.SqlDataAdapter("Select * from ProductSizes", ConnectionString)
        dbadp.fill(dTable)
        dbadp.dispose()
        Session("dTable") = dTable
        'then the ddl code here
        ddlDirSize.DataSource = DTable
        ddlDirSize.DataTextField = "OptionType"
        ddlDirSize.DataValueField = "OptionID"

        'SelectedIndex changed
        Dim dTable As Data.DataTable = Session("dTable")
        If Not IsNothing(dTable) Then
            'the defaultview code here.
            Dim ID As Integer = ddlDirSize.SelectedValue
            dTable.DefaultView.RowFilter = "OptionID=" & ID
            If dTable.DefaultView.Count = 1 Then
                txtDirRate.Text = dTable.DefaultView.item(0).item("OptionPrice")
            End If
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
I suppose the following code is in page_load event
        'Create data table
        Dim ConnectionString As String
        ConnectionString = "Server=FMASQL;database=HidingInformation"
        Dim dTable As New Data.DataTable
        Dim dbadp As New Data.SqlClient.SqlDataAdapter("Select * from ProductSizes", ConnectionString)
        dbadp.fill(dTable)
        dbadp.dispose()
        Session("dTable") = dTable
        'then the ddl code here
        ddlDirSize.DataSource = DTable
        ddlDirSize.DataTextField = "OptionType"
        ddlDirSize.DataValueField = "OptionID"

and following is in selectedindex changed event
'SelectedIndex changed
        Dim dTable As Data.DataTable = Session("dTable")
        If Not IsNothing(dTable) Then
            'the defaultview code here.
            Dim ID As Integer = ddlDirSize.SelectedValue
            dTable.DefaultView.RowFilter = "OptionID=" & ID
            If dTable.DefaultView.Count = 1 Then
                txtDirRate.Text = dTable.DefaultView.item(0).item("OptionPrice")
            End If

Then you should not get this error but still you can change the following line
Dim dTable As Data.DataTable = Session("dTable")
to this
dTable = Session("dTable")
0
 

Author Comment

by:Albee_J
Comment Utility
Ok, I have something wrong somewhere I am trying to assign the value to a variable and pull it in to be calculated in a subroutine CalcDirectory ()

I am getting a 0


Partial Class Default2
    Inherits System.Web.UI.Page
    Sub Page_Load()
        Dim DirValue As String
        If ckDirAd.Checked Then
            DirValue = "1"
        Else
            DirValue = ""
        End If

        'Create data table
        Dim ConnectionString As String
        ConnectionString = "Server=FMASQL;database=HidingInformation"
        Dim dTable As New Data.DataTable
        Dim dbadp As New Data.SqlClient.SqlDataAdapter("Select * from ProductSizes", ConnectionString)
        dbadp.Fill(dTable)
        dbadp.Dispose()
        Session("dTable") = dTable
        'then the ddl code here
        ddlDirSize.DataSource = DTable
        ddlDirSize.DataTextField = "OptionType"
        ddlDirSize.DataValueField = "OptionID"


    End Sub

    Sub CalcMultiple()
        Const Multiple As Double = 500

        If ckMultiple.Checked = True Then txtMultipleRate.Text = FormatCurrency(Multiple)

    End Sub
    Sub CalcDirectory()

        Dim SizePrice As Integer

        If ckDirAd.Checked = True And ckDirSpecial.Checked = False Then
            'I forced a value in here, this really should be the Price of the Size selected the ddlDirSize
            txtDirRate.Text = FormatCurrency(SizePrice)
        ElseIf ckDirAd.Checked = True And ckDirSpecial.Checked = True Then
            txtDirRate.Text = FormatCurrency(500 * 1.12)
        ElseIf ckDirAd.Checked = False And ckDirSpecial.Checked = False Then
            txtDirRate.Text = ""
        End If



    End Sub

    Protected Sub txtMultiple_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckMultiple.CheckedChanged

        If ckMultiple.Checked = True Then
            lblSecondary.Text = "Secondary Company Name:"
            lblSecondary.ToolTip = "Enter in Secondary company name as it is to be shown in directory/web"
            lblMultipleIn.Visible = True
            ckMultipleIn.Visible = True
            lblMultipleRate.Visible = True
            txtMultipleRate.Visible = True
            CalcMultiple()

        Else
            lblSecondary.Text = "Other Advertiser:"
            lblSecondary.ToolTip = "Not Exhibiting or sharing a booth, list company name"
            lblMultipleIn.Visible = False
            ckMultipleIn.Visible = False
            lblMultipleRate.Visible = False
            txtMultipleRate.Visible = False
     
        End If
    End Sub

    Protected Sub ckDirAd_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirAd.CheckedChanged
        CalcDirectory()
    End Sub

    Protected Sub ckDirSpecial_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirSpecial.CheckedChanged
        CalcDirectory()
    End Sub

    Protected Sub ddlDirSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDirSize.SelectedIndexChanged
        CalcDirectory()
        'SelectedIndex changed
        Dim dTable As Data.DataTable = Session("dTable")
        If Not IsNothing(dTable) Then
            Dim ID As Integer = ddlDirSize.SelectedValue
            dTable.DefaultView.RowFilter = "OptionID=" & ID
            If dTable.DefaultView.Count = 1 Then
                Dim SizePrice As Integer
                SizePrice = dTable.DefaultView.Item(0).Item("OptionPrice")
            End If
        End If
    End Sub
End Class

0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
After this line in selectedindexchanged
SizePrice = dTable.DefaultView.Item(0).Item("OptionPrice")
add this
Session("SizePrice") = SizePrice

then in the caldir code change this
txtDirRate.Text = FormatCurrency(SizePrice)
to this
txtDirRate.Text = FormatCurrency(Session("SizePrice"))


Remember that in ASP.NET, variables loose their values between postbacks. So we need to use Session to persist these values.
0
 

Author Comment

by:Albee_J
Comment Utility
I added all the code and I am still gettting nothing in the txtDirRate.text box


Partial Class Default2
    Inherits System.Web.UI.Page
    Sub Page_Load()
        Dim DirValue As String
        If ckDirAd.Checked Then
            DirValue = "1"
        Else
            DirValue = ""
        End If

        'Create data table
        Dim ConnectionString As String
        ConnectionString = "Server=FMASQL;database=ProductSizes;User FMA-dbo=xxx;Password=xxx:)"
        Dim dTable As New Data.DataTable
        Dim dbadp As New Data.SqlClient.SqlDataAdapter("Select * from ProductSizes", ConnectionString)
        dbadp.Fill(dTable)
        dbadp.Dispose()
        Session("dTable") = dTable
        'then the ddl code here
        ddlDirSize.DataSource = DTable
        ddlDirSize.DataTextField = "OptionType"
        ddlDirSize.DataValueField = "OptionID"


    End Sub

    Sub CalcMultiple()
        Const Multiple As Double = 500

        If ckMultiple.Checked = True Then txtMultipleRate.Text = FormatCurrency(Multiple)

    End Sub
    Sub CalcDirectory()

        If ckDirAd.Checked = True And ckDirSpecial.Checked = False Then
            'I forced a value in here, this really should be the Price of the Size selected the ddlDirSize
            txtDirRate.Text = FormatCurrency(Session("SizePrice"))
        ElseIf ckDirAd.Checked = True And ckDirSpecial.Checked = True Then
            txtDirRate.Text = FormatCurrency(Session("SizePrice") * 1.12)
        ElseIf ckDirAd.Checked = False And ckDirSpecial.Checked = False Then
            txtDirRate.Text = ""
        End If



    End Sub

    Protected Sub txtMultiple_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckMultiple.CheckedChanged

        If ckMultiple.Checked = True Then
            lblSecondary.Text = "Secondary Company Name:"
            lblSecondary.ToolTip = "Enter in Secondary company name as it is to be shown in directory/web"
            lblMultipleIn.Visible = True
            ckMultipleIn.Visible = True
            lblMultipleRate.Visible = True
            txtMultipleRate.Visible = True
            CalcMultiple()

        Else
            lblSecondary.Text = "Other Advertiser:"
            lblSecondary.ToolTip = "Not Exhibiting or sharing a booth, list company name"
            lblMultipleIn.Visible = False
            ckMultipleIn.Visible = False
            lblMultipleRate.Visible = False
            txtMultipleRate.Visible = False
     
        End If
    End Sub

    Protected Sub ckDirAd_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirAd.CheckedChanged
        CalcDirectory()
    End Sub

    Protected Sub ckDirSpecial_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirSpecial.CheckedChanged
        CalcDirectory()
    End Sub

    Protected Sub ddlDirSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDirSize.SelectedIndexChanged

        'SelectedIndex changed
        Dim dTable As Data.DataTable = Session("dTable")
        If Not IsNothing(dTable) Then
            Dim ID As Integer = ddlDirSize.SelectedValue
            dTable.DefaultView.RowFilter = "OptionID=" & ID
            If dTable.DefaultView.Count = 1 Then
                Dim SizePrice As Integer
                SizePrice = dTable.DefaultView.Item(0).Item("OptionPrice")
                Session("SizePrice") = SizePrice

            End If
        End If
        CalcDirectory()
    End Sub
End Class
0
 

Author Comment

by:Albee_J
Comment Utility
Rut Roh can you comment out my Connection String code??
0
 

Author Comment

by:Albee_J
Comment Utility
I think it is the connection string not working right.  

ConnectionString = "Server=FMASQL;database=ProductSizes;User ID=***;Password=***"
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Step through the code and see if dTable gets any rows. Also step through and check the count of the defaultview after filtering. Or you can use some label on the page to output these values.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Albee_J
Comment Utility
I am trying to set break points, but when I run the application it never breaks to take me back to see what has happened.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Use labels on page and set text of those labels in this code.
0
 

Author Comment

by:Albee_J
Comment Utility
I apologize, but I do not know what you mean.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
I mean put a label on the aspx page somewhere. Then within the code in page load after this line
dbadp.Fill(dTable)
use this
Label1.Text = "Table Row Count: " & dTable.Rows.Count

And in selectedindexchangedevent
after this line
dTable.DefaultView.RowFilter = "OptionID=" & ID
write
Label1.Text &= ", Filtered Count: " & dTable.DefaultView.Count
0
 

Author Comment

by:Albee_J
Comment Utility
Ok, did that. Nothing is populating into the label at all.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Can you show the full code now? Also, does the page disappear and postback when you select some value from drop down list?
0
 

Author Comment

by:Albee_J
Comment Utility
Yes the page does do a refresh when I select a value from the drop down list.


Partial Class Default2
    Inherits System.Web.UI.Page
    Sub Page_Load()
        Dim DirValue As String
        If ckDirAd.Checked Then
            DirValue = "1"
        Else
            DirValue = ""
        End If

        'Create data table
        Dim dTable As New Data.DataTable
        Dim dbadp As New Data.SqlClient.SqlDataAdapter("Select * from ProductSizes", "Server=FMASQL;database=ProductSizes;User ID=xxx;Password=xxx")
        dbadp.Fill(dTable)
        lblTest.Text = "Table Row Count: " & dTable.Rows.Count
        dbadp.Dispose()
        Session("dTable") = dTable
        'then the ddl code here
        ddlDirSize.DataSource = dTable
        ddlDirSize.DataTextField = "OptionType"
        ddlDirSize.DataValueField = "OptionID"
    End Sub

    Sub CalcMultiple()
        Const Multiple As Double = 500

        If ckMultiple.Checked = True Then txtMultipleRate.Text = FormatCurrency(Multiple)

    End Sub
    Sub CalcDirectory()

        If ckDirAd.Checked = True And ckDirSpecial.Checked = False Then
            'I forced a value in here, this really should be the Price of the Size selected the ddlDirSize
            txtDirRate.Text = FormatCurrency(Session("SizePrice"))
            'txtDirRate.Text = FormatCurrency(500)
        ElseIf ckDirAd.Checked = True And ckDirSpecial.Checked = True Then
            txtDirRate.Text = FormatCurrency(Session("SizePrice"))
            'txtDirRate.Text = FormatCurrency(500 * 1.12)
        ElseIf ckDirAd.Checked = False And ckDirSpecial.Checked = False Then
            txtDirRate.Text = ""
        End If



    End Sub
    Protected Sub ddlDirSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDirSize.SelectedIndexChanged

        'SelectedIndex changed
        Dim dTable As Data.DataTable = Session("dTable")
        If Not IsNothing(dTable) Then
            Dim ID As Integer = ddlDirSize.SelectedValue
            dTable.DefaultView.RowFilter = "OptionID=" & ID
            lblTest.Text &= ", Filtered Count: " & dTable.DefaultView.Count
            If dTable.DefaultView.Count = 1 Then
                Dim SizePrice As Integer
                SizePrice = dTable.DefaultView.Item(0).Item("OptionPrice")
                Session("SizePrice") = SizePrice

            End If
        End If
        CalcDirectory()
    End Sub

    Protected Sub txtMultiple_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckMultiple.CheckedChanged

        If ckMultiple.Checked = True Then
            lblSecondary.Text = "Secondary Company Name:"
            lblSecondary.ToolTip = "Enter in Secondary company name as it is to be shown in directory/web"
            lblMultipleIn.Visible = True
            ckMultipleIn.Visible = True
            lblMultipleRate.Visible = True
            txtMultipleRate.Visible = True
            CalcMultiple()

        Else
            lblSecondary.Text = "Other Advertiser:"
            lblSecondary.ToolTip = "Not Exhibiting or sharing a booth, list company name"
            lblMultipleIn.Visible = False
            ckMultipleIn.Visible = False
            lblMultipleRate.Visible = False
            txtMultipleRate.Visible = False
     
        End If
    End Sub

    Protected Sub ckDirAd_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirAd.CheckedChanged
        CalcDirectory()
    End Sub

    Protected Sub ckDirSpecial_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirSpecial.CheckedChanged
        CalcDirectory()
    End Sub


End Class
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
oh right. Put all the code in page load event in this condition

If Not Page.IsPostBack Then
'All code here
End If
0
 

Author Comment

by:Albee_J
Comment Utility
I did that, still no dice.

    Sub Page_Load()

        Dim DirValue As String
        If ckDirAd.Checked Then
            DirValue = "1"
        Else
            DirValue = ""
        End If
        If Not Page.IsPostBack Then
            'Create data table
            Dim dTable As New Data.DataTable
            Dim dbadp As New Data.SqlClient.SqlDataAdapter("Select * from ProductSizes", "Data Source=FMASQL;Initial Catalog=FabtechSales;Persist Security Info=True;User ID=**;Password=**")
            dbadp.Fill(dTable)
            lblTest.Text = "Table Row Count: " & dTable.Rows.Count
            dbadp.Dispose()
            Session("dTable") = dTable
            'then the ddl code here
            ddlDirSize.DataSource = dTable
            ddlDirSize.DataTextField = "OptionType"
            ddlDirSize.DataValueField = "OptionID"
        End If
    End Sub
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
It is really strange that lblTest does not reflect the assigned text. It means that the code is not executing. You need to play with the code to isolate the problem. For example, instead of label, use a list box and at different stages in the page, for example when the page loads or when the selectedindexchanged event is started, add items to the listbox reflect the stage at which the code is executing. This way you could follow the path of the execution. If you set breakpoint, you should be able to debug it. Make sure that this page is the startup page (right click in solution explorer on the page) and you use the play button from the toolbar and that the debug="true" in web.config.
0
 

Author Comment

by:Albee_J
Comment Utility
I agree. I will conduct some tests and see what I  can find out. I will post back here when I do.
0
 

Author Comment

by:Albee_J
Comment Utility
My page Load isn't even firing I have no idea why. I put a test text box to show on page load. Nothing...
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Your page load event handler currently looks like this
Sub Page_Load()

But it should look like this

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
0
 

Author Comment

by:Albee_J
Comment Utility
Ah *sigh* that is what it was.  Ok everything is working. The only problem I have now is when I choose a value in the drop down list, it does populate txtDirRate.text with the value, but the dropdownlist turns blank and is not retaining the selection...


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        txtTest.Text = "Page Load Worked"

        If ckDirAd.Checked Then

            txtDirProdID.Text = "1"

        Else

            txtDirProdID.Text = "0"

        End If
 

        'If Not Page.IsPostBack Then

        'Create data table

        Dim dTable As New Data.DataTable

        Dim dbadp As New Data.SqlClient.SqlDataAdapter("Select * from ProductSizes", "Data Source=FMASQL;Initial Catalog=FabtechSales;Persist Security Info=True;User ID=**;Password=**")

        dbadp.Fill(dTable)

        '  txtTest.Text = "Table Row Count: " & dTable.Rows.Count

        dbadp.Dispose()

        Session("dTable") = dTable

        'then the ddl code here

        'ddlDirSize.DataSource = dTable

        ddlDirSize.DataTextField = "OptionType"

        ddlDirSize.DataValueField = "OptionID"

        'End If

    End Sub
 
 

    Protected Sub txtMultiple_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckMultiple.CheckedChanged
 

        If ckMultiple.Checked = True Then

            lblSecondary.Text = "Secondary Company Name:"

            lblSecondary.ToolTip = "Enter in Secondary company name as it is to be shown in directory/web"

            lblMultipleIn.Visible = True

            ckMultipleIn.Visible = True

            lblMultipleRate.Visible = True

            txtMultipleRate.Visible = True

            CalcMultiple()
 

        Else

            lblSecondary.Text = "Other Advertiser:"

            lblSecondary.ToolTip = "Not Exhibiting or sharing a booth, list company name"

            lblMultipleIn.Visible = False

            ckMultipleIn.Visible = False

            lblMultipleRate.Visible = False

            txtMultipleRate.Visible = False
 

        End If

    End Sub
 

   Sub CalcDirectory()
 

        If ckDirAd.Checked = True And ckDirSpecial.Checked = False Then

            txtDirRate.Text = FormatCurrency(Session("SizePrice"))

        ElseIf ckDirAd.Checked = True And ckDirSpecial.Checked = True Then

            txtDirRate.Text = FormatCurrency(Session("SizePrice") * 1.12)

        ElseIf ckDirAd.Checked = False And ckDirSpecial.Checked = False Then

            txtDirRate.Text = ""

        End If
 
 
 

    End Sub

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Its because you have commented out this condition

        'If Not Page.IsPostBack Then

so each time page is posted back, the list is repopulated and reset!
0
 

Author Comment

by:Albee_J
Comment Utility
*Blush* My apologies, that was it.... Thank you sooo much for your help and patience CodeCruiser...

You REALLY helped me over a tough hurdle.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
I am glad your problem is solved.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now