Solved

Creating DataBound CheckBoxLists

Posted on 2007-12-05
11
655 Views
Last Modified: 2013-11-26
Yes I like to know in vb and asp.net to Creating DataBound CheckBoxLists.
I am trying to incert this into a script another developer left for me.

Can you put this together thanks
' vb script is wrong need someone to help me fix it but the connection 'string is correct A1SConnString
Private Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SInsertSalesStoreItems", conn)
 
    CheckBoxList1.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection);
    CheckBoxList1.DataBind();
 
    End Sub
 
 
'aspnet front end
<asp:CheckBoxList id="CheckBoxList1" Runat="Server"  RepeatDirection="Horizontal" AutoPostBack="True" DataTextField="interest" DataValueField="Interest"></asp:CheckBoxList>

Open in new window

0
Comment
Question by:sevensnake77
  • 6
  • 3
  • 2
11 Comments
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20411937
Use this

Private Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
      conn.Open()

        Dim cmd As New SqlCommand("spA1SInsertSalesStoreItems", conn)
 
          CheckBoxList1.DataSource = objCmd.ExecuteReader()
          CheckBoxList1.DataBind()
 
End Sub
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20411957
Keep the front end code as it is. No change required there.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 20412049
but the vb code I do not really understand, I have a basic understanding but cannot get it to connect
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 9

Author Comment

by:sevensnake77
ID: 20412194
why would you answer my question with a question like that.
0
 
LVL 12

Expert Comment

by:needo_jee
ID: 20412210
you are trying to pupulate checkboxlist on its own change event?
when its going to fire when there is no item in it.

why not populating at page load inside postback



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then       
 Try
Dim conn As New SqlConnection(Application("A1SConnString"))
Dim objCmdAs New SqlCommand("spA1SInsertSalesStoreItems", conn)
cmd.commandType=CommandType.StoredProcedure
conn.open()
     CheckBoxList1.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection);
    CheckBoxList1.DataBind();
       Catch ex As Exception
'message
        End Try
end if

Open in new window

0
 
LVL 12

Expert Comment

by:needo_jee
ID: 20412225
End sub was missing in last code example
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then       
 Try
Dim conn As New SqlConnection(Application("A1SConnString"))
Dim objCmdAs New SqlCommand("spA1SInsertSalesStoreItems", conn)
cmd.commandType=CommandType.StoredProcedure
conn.open()
     CheckBoxList1.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection);
    CheckBoxList1.DataBind();
       Catch ex As Exception
'message
        End Try
end if
End Sub

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 20412358
Well this is an insert statement Dim objCmdAs New SqlCommand("spA1SInsertSalesStoreItems", conn)
But I want to bound it I am getting all kind of errors CheckBoxList1 not declared but I delcared it

<asp:CheckBoxList id="Checkboxlist1" Runat="Server"  RepeatDirection="Horizontal" AutoPostBack="True" DataTextField="interest" DataValueField="Interest"></asp:CheckBoxList>

id Checkboxlist1

need a better solution please


                                                            
0
 
LVL 12

Accepted Solution

by:
needo_jee earned 500 total points
ID: 20412818
not sure what you want exactly . using an insert statement to bind a checkboxlist?
what is purpose of using checkboxList ? to display data?
is it possible to post ASPX + .VB code for that form?
thanks
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 20412871
No I just want to bind the  Checkbox to a datagrid I have already.

Also I get and error saying A field or property with the name 'store' was not found on the selected datasource.

But also if you can get me to bind it noone could so far.
<asp:datagrid id="DataGrid1" runat="server" Width="1004px" AutoGenerateColumns="False" ShowHeader="false"
								CellPadding="1" ItemStyle-Height="25px" ItemStyle-CssClass="prgdata" AlternatingItemStyle-BackColor="white"
								cssclass="prgdata" AllowPaging="True" PageSize="7">
								<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
								<ItemStyle Height="25px" CssClass="prgdata"></ItemStyle>
								<HeaderStyle Height="0px"></HeaderStyle>
								<Columns>
									<asp:TemplateColumn>
										<ItemTemplate>
											<asp:ImageButton id="ImageButton1" runat="server" Width="16px" AlternateText="Delete Item From The List" ImageUrl="../Images/delete2.png" OnCommand="DeleteItems" CommandArgument='<%# Container.DataItem("ItemId") %>'>
											</asp:ImageButton>
										</ItemTemplate>
									</asp:TemplateColumn>
									<asp:BoundColumn Visible="False" DataField="ItemID"></asp:BoundColumn>
									<asp:BoundColumn DataField="UPC">
										<ItemStyle Width="125px"></ItemStyle>
									</asp:BoundColumn>
									<asp:BoundColumn DataField="Description">
										<ItemStyle HorizontalAlign="Left" Width="200px"></ItemStyle>
									</asp:BoundColumn>
									<asp:BoundColumn DataField="Quantity">
										<ItemStyle Width="85px"></ItemStyle>
									</asp:BoundColumn>
									<asp:BoundColumn DataField="Price">
										<ItemStyle Width="100px"></ItemStyle>
									</asp:BoundColumn>
									<asp:BoundColumn DataField="CreatedDate">
										<ItemStyle Width="170px"></ItemStyle>
										</asp:BoundColumn>
											<asp:BoundColumn  HeaderStyle-HorizontalAlign="Center" DataField="" />
										<asp:TemplateColumn>	
										<ItemTemplate>
										<asp:RadioButton id="RadioButton1" ></asp:RadioButton>
										<asp:RadioButton id="RadioButton2" ></asp:RadioButton>
										<asp:CheckBoxList id="Mycheck" Runat="Server"  RepeatDirection="Horizontal" AutoPostBack="True" DataTextField="interest" DataValueField="Interest"></asp:CheckBoxList>
										<asp:CheckBoxList id="Checkboxlist2" AutoPostBack="True" RepeatDirection="Horizontal" runat="server" Font-Size="8">
Imports System
Imports System.Data
Imports System.Data.SqlClient
 
Public Class SalesTPR
    Inherits System.Web.UI.Page
 
#Region " Web Form Designer Generated Code "
 
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
 
    End Sub
    Protected WithEvents DoneButton As System.Web.UI.WebControls.Button
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
    Protected WithEvents UPCCode As System.Web.UI.WebControls.TextBox
    Protected WithEvents Description As System.Web.UI.WebControls.TextBox
    Protected WithEvents Size As System.Web.UI.WebControls.TextBox
    Protected WithEvents Qty As System.Web.UI.WebControls.TextBox
    Protected WithEvents Price As System.Web.UI.WebControls.TextBox
    Protected WithEvents SizeMeasureList As System.Web.UI.WebControls.DropDownList
    Protected WithEvents WebImageButton1 As Infragistics.WebUI.WebDataInput.WebImageButton
    Protected WithEvents WebImageButton3 As Infragistics.WebUI.WebDataInput.WebImageButton
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
    Protected WithEvents WebAsyncRefreshPanel1 As Infragistics.WebUI.Misc.WebAsyncRefreshPanel
 
    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object
 
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub
 
#End Region
    Dim strselecteditems As String = Nothing
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            RetrieveSalesTPRItems()
            SetFocus(UPCCode, Me)
            LoadSizeMeasure()
 
            With lblMessage
                lblMessage.Visible = True
                .CssClass = "labelGreen"
                .Text = "Total Pages: " & DataGrid1.PageCount.ToString
            End With
 
            Dim StoreList() As String
            Dim I As Integer = 0
 
            StoreList = Session("Stores")
 
            For I = 0 To UBound(StoreList)
                'ListBox1.Items.Add(AddIntoDataStructureofStorelist(StoreList(I)).StoreId.ToString)
                ListBox1.Items.Add(StoreList(I).ToString)
            Next
 
            Me.UPCCode.BackColor = System.Drawing.Color.White
            Me.Description.BackColor = System.Drawing.Color.White
            Me.Size.BackColor = System.Drawing.Color.White
            Me.Qty.BackColor = System.Drawing.Color.White
            Me.Price.BackColor = System.Drawing.Color.White
        End If
    End Sub
 
    Private Sub UPCCode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UPCCode.TextChanged
        'Searching for UPC code
        If Me.UPCCode.Text <> "" And IsValidIntegerRequired(Me.UPCCode.Text) Then
 
            Dim NameValueOut As String
            Dim SizeValueOut As String
            Dim UOMValueOut As String
 
            Dim conn As New SqlConnection(Application("A1SConnString"))
            Dim cmd As New SqlCommand("spA1SGetUPCCode", conn)
            cmd.CommandType = CommandType.StoredProcedure
            Dim sqlDR As SqlDataReader
            Dim prm As SqlParameter
 
            conn.Open()
            prm = cmd.Parameters.Add("@UPC", SqlDbType.Text)
            prm.Value = UPCCode.Text
            sqlDR = cmd.ExecuteReader
 
            While sqlDR.Read
                NameValueOut = sqlDR("Name")
                SizeValueOut = sqlDR("Size")
                UOMValueOut = sqlDR("UOM")
            End While
 
            If sqlDR.HasRows Then
 
                Me.Description.Text = NameValueOut
                Me.Size.Text = SizeValueOut
                'SizeMeasureList.Items.Clear()
                'SizeMeasureList.Items.Add(UOMValueOut)
                LoadSizeMeasure(UOMValueOut) 'Giving the user option to change SizeMeasureID
 
 
                lblMessage.Visible = False
                Me.Description.ReadOnly = True
                Me.Size.ReadOnly = True
                Me.UPCCode.ReadOnly = True
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
 
            Else
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "The UPC Code could not be found matching the search term  '" & UPCCode.Text & "' . Please Enter Item Description."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.PeachPuff
                Me.Size.BackColor = System.Drawing.Color.White
            End If
 
            'Clean Up
            If (Not sqlDR Is Nothing) Then
                If (sqlDR.IsClosed) Then
                    sqlDR.Close()
                End If
            End If
            If (Not conn Is Nothing) Then
                If conn.State <> ConnectionState.Closed Then conn.Close()
                conn.Dispose()
            End If
            If Not cmd Is Nothing Then cmd.Dispose()
            'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            ' Searching for Manual(non-Krasdale ID) code
        ElseIf CheckIfManualID(Me.UPCCode.Text.Chars(0)) Then
 
            Dim conn As New SqlConnection(Application("A1SConnString"))
            Dim cmd As New SqlCommand("spA1SGetWHCode", conn)
            cmd.CommandType = CommandType.StoredProcedure
            Dim sqlDR As SqlDataReader
            Dim prm As SqlParameter
 
            conn.Open()
            prm = cmd.Parameters.Add("@WHCode", SqlDbType.Text)
            prm.Value = UPCCode.Text
 
            prm = cmd.Parameters.Add("@UserID", SqlDbType.VarChar, 15)
            prm.Value = Request.Cookies("A1S")("UID")
 
            sqlDR = cmd.ExecuteReader
            sqlDR.Read()
 
            If sqlDR.HasRows Then
 
                Me.Description.Text = SqlDR("Description")
                SizeMeasureList.Items.Clear()
                Me.SizeMeasureList.Enabled = False
                'Me.DeleteBtn.Enabled = False
 
                lblMessage.Visible = False
                Me.Description.ReadOnly = True
                Me.Size.ReadOnly = True
                Me.UPCCode.ReadOnly = True
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = Nothing
 
            Else
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "The warehouse code could not be found matching the search term  '" & UPCCode.Text & "' . Please reenter your warehouse code."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
            End If
 
            'Clean Up
            If (Not sqlDR Is Nothing) Then
                If (sqlDR.IsClosed) Then
                    sqlDR.Close()
                End If
            End If
            If (Not conn Is Nothing) Then
                If conn.State <> ConnectionState.Closed Then conn.Close()
                conn.Dispose()
            End If
            If Not cmd Is Nothing Then cmd.Dispose()
            'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            'If UPC code and WHCode code were not found display error message
        Else
            With lblMessage
                lblMessage.Visible = True
                .CssClass = "labelRed"
                .Text = "The UPC Code must have only whole numbers. Please reenter your UPC Code."
            End With
        End If
    End Sub
    Public Function LoadSizeMeasure(Optional ByVal SelectedVal As String = Nothing)
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As SqlCommand
        Dim prm As SqlParameter
 
        cmd = New SqlCommand("spA1SGetSizeMeasure", conn)
        cmd.CommandType = CommandType.StoredProcedure
 
        Dim oRDR As SqlDataReader
        cmd.CommandTimeout = 120 'Number of seconds to wait for a response.
 
        conn.Open()
        oRDR = cmd.ExecuteReader(CommandBehavior.Default)
 
        SizeMeasureList.Items.Clear()
 
        While oRDR.Read
            SizeMeasureList.Items.Add(oRDR("ABRV"))
            If SelectedVal = oRDR("ABRV") Then SizeMeasureList.SelectedValue = oRDR("ABRV")
            SizeMeasureList.Items(SizeMeasureList.Items.Count - 1).Value = oRDR("SizeMeasureID")
        End While
 
        'Clean Up
        If (Not oRDR Is Nothing) Then
            If Not (oRDR.IsClosed) Then
                oRDR.Close()
            End If
        End If
        oRDR = Nothing
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
    End Function
 
    Private Sub WebImageButton1_Click(ByVal sender As System.Object, ByVal e As Infragistics.WebUI.WebDataInput.ButtonEventArgs) Handles WebImageButton1.Click
        If Me.UPCCode.Text <> "" Then
            'If UPC Code is entered then validate and save
            If ValidatingInputForUPCCode() = True Then
                If ListBox1.SelectedIndex <> -1 Then
                    If VerifyStores() = 1 Then
                        UpdateSalesTPRTable()
                        RetrieveSalesTPRItems()
                        InitializeForm()
                        With lblMessage
                            lblMessage.Visible = True
                            .CssClass = "labelGreen"
                            .Text = "The Sale Item was inserted successfully."
                        End With
                        Me.UPCCode.BackColor = System.Drawing.Color.White
                        Me.Description.BackColor = System.Drawing.Color.White
                        Me.Size.BackColor = System.Drawing.Color.White
                        Me.Qty.BackColor = System.Drawing.Color.White
                        Me.Price.BackColor = System.Drawing.Color.White
                        Me.ListBox1.BackColor = System.Drawing.Color.White
                    Else
                        DisplayErrorMessage(7)
                    End If
                Else
                    DisplayErrorMessage(8)
                End If
            End If
        Else
            DisplayErrorMessage(0)
        End If
    End Sub
 
    Private Sub WebImageButton3_Click(ByVal sender As System.Object, ByVal e As Infragistics.WebUI.WebDataInput.ButtonEventArgs) Handles WebImageButton3.Click
        InitializeForm()
    End Sub
    Private Sub InitializeForm()
        Me.lblMessage.Text = Nothing
        Me.UPCCode.Text = Nothing
        Me.Description.Text = Nothing
        Me.Size.Text = Nothing
        Me.Qty.Text = Nothing
        Me.Price.Text = Nothing
        Me.UPCCode.ReadOnly = False
        Me.Description.ReadOnly = False
        Me.Size.ReadOnly = False
 
        Me.UPCCode.BackColor = System.Drawing.Color.White
        Me.Description.BackColor = System.Drawing.Color.White
        Me.Size.BackColor = System.Drawing.Color.White
        Me.Qty.BackColor = System.Drawing.Color.White
        Me.Price.BackColor = System.Drawing.Color.White
        Me.SizeMeasureList.Enabled = True
        SetFocus(UPCCode, Me)
        SizeMeasureList.Items.Clear()
        LoadSizeMeasure()
    End Sub
    Private Function ValidatingInputForUPCCode() As Boolean
 
        Dim bChecking(6) As Boolean
 
        If Me.UPCCode.Text <> "" And IsValidIntegerRequired(Me.UPCCode.Text) Then bChecking(0) = True Else bChecking(0) = False
        If Me.Description.Text <> "" Then bChecking(1) = True Else bChecking(1) = False
        If Me.Size.Text <> "" And IsValidDoubleRequired(Me.Size.Text) Then bChecking(2) = True Else bChecking(2) = False
        If Me.SizeMeasureList.SelectedValue <> "" Then bChecking(3) = True Else bChecking(3) = False
        If Me.Qty.Text <> "" And IsValidIntegerRequired(Me.Qty.Text) Then bChecking(4) = True Else bChecking(4) = False
        If Me.Price.Text <> "" And IsValidDoubleRequired(Me.Price.Text) Then bChecking(5) = True Else bChecking(5) = False
        If VerifyUnicUPCCode(Me.UPCCode.Text) Then bChecking(6) = True Else bChecking(6) = False
 
        Dim i As Integer
        For i = 0 To 6
 
            If bChecking(i) = True Then
                ValidatingInputForUPCCode = True
            Else : ValidatingInputForUPCCode = i
                DisplayErrorMessage(i)
                ValidatingInputForUPCCode = False
                Exit For
            End If
 
        Next
        Return ValidatingInputForUPCCode
    End Function
    Private Function DisplayErrorMessage(ByVal MsgIndex As Integer)
 
        Select Case MsgIndex
            Case 0
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "UPC Code is a required field and must be a whole number. Please reenter your UPC Code."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.PeachPuff
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 1
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Description is a required field. Please reenter your Description."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.PeachPuff
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 2
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Size is a required field and must be numeric. Please reenter your Size."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.PeachPuff
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 3
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Size Measure is a required field. Please reenter your Size Measure."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 4
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Sale Quantity is a required field and must be a whole number other than 0. Please reenter your Sale Quantity."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.PeachPuff
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 5
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Sale Price is a required field and must be a number other than 0. Please reenter your Sale Price."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.PeachPuff
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 6
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "The UPCCode that was entered already exists. Please reenter your UPCCode."
                End With
                Me.UPCCode.BackColor = System.Drawing.Color.PeachPuff
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.White
 
            Case 7
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "The Stores that you have selected do not belong to the same Program. Please reselect your Stores."
                End With
 
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.PeachPuff
 
            Case 8
                With lblMessage
                    lblMessage.Visible = True
                    .CssClass = "labelRed"
                    .Text = "Please select at least one Store from the list."
                End With
 
                Me.UPCCode.BackColor = System.Drawing.Color.White
                Me.Description.BackColor = System.Drawing.Color.White
                Me.Size.BackColor = System.Drawing.Color.White
                Me.Qty.BackColor = System.Drawing.Color.White
                Me.Price.BackColor = System.Drawing.Color.White
                Me.ListBox1.BackColor = System.Drawing.Color.PeachPuff
        End Select
    End Function
    Public Function UpdateSalesTPRTable()
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SInsertSalesTPRItems", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim prm As SqlParameter
 
        prm = New SqlParameter("@UPC", SqlDbType.VarChar, 50)
        prm.Direction = ParameterDirection.Input
        prm.Value = Me.UPCCode.Text 'If UPC is not found Adding to SalesTPR and upc.dbo.uProduct
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Description", SqlDbType.VarChar, 60)
        prm.Direction = ParameterDirection.Input
        prm.Value = Me.Description.Text     'If UPC is not found Adding to SalesTPR and upc.dbo.uProduct
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@SizeUnit", SqlDbType.VarChar, 8)
        prm.Direction = ParameterDirection.Input
        prm.Value = Me.Size.Text            'If UPC is not found Adding to SalesTPR and upc.dbo.uProduct
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@SizeMeasureID", SqlDbType.BigInt)
        prm.Direction = ParameterDirection.Input
        prm.Value = CheckSizeMeasureID()
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Quantity", SqlDbType.Decimal)
        prm.Direction = ParameterDirection.Input
        prm.Value = Convert.ToDecimal(Me.Qty.Text)
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Price", SqlDbType.Decimal)
        prm.Direction = ParameterDirection.Input
        prm.Value = Convert.ToDecimal(Me.Price.Text)
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Active", SqlDbType.TinyInt)
        prm.Direction = ParameterDirection.Input
        prm.Value = 1
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@CreatedDate", SqlDbType.DateTime)
        prm.Direction = ParameterDirection.Input
        prm.Value = Now.ToLongTimeString
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@ModifiedDate", SqlDbType.DateTime)
        prm.Direction = ParameterDirection.Input
        prm.Value = Now.ToLongTimeString
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@ActiveDate", SqlDbType.DateTime)
        prm.Direction = ParameterDirection.Input
        prm.Value = Now.ToLongTimeString
        cmd.Parameters.Add(prm)
 
        'prm = New SqlParameter("@UOM", SqlDbType.VarChar, 4)
        'prm.Direction = ParameterDirection.Input
        'prm.Value = Me.SizeMeasureList.SelectedItem.Text    'Adding to upc.dbo.uProduct if UPC doesn't exist
        'cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@UserID", SqlDbType.VarChar, 50)
        prm.Direction = ParameterDirection.Input
        prm.Value = ReadCookie(Tokens.UserId)
        cmd.Parameters.Add(prm)
 
        prm = New SqlParameter("@Stores", SqlDbType.VarChar, 50)
        prm.Direction = ParameterDirection.Input
        prm.Value = strselecteditems
        cmd.Parameters.Add(prm)
 
        conn.Open()
        cmd.ExecuteNonQuery()
 
        If conn.State <> ConnectionState.Closed Then conn.Close()
        If Not conn Is Nothing Then conn.Dispose()
        If Not cmd Is Nothing Then cmd.Dispose()
        prm = Nothing
 
    End Function
    Private Function CheckSizeMeasureID(Optional ByVal SizeMeasureID As String = Nothing) As Integer
 
        Dim SzMeasureID As Integer
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SCheckSizeMeasure", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim sqlDR As SqlDataReader
        Dim prm As SqlParameter
 
        conn.Open()
        prm = cmd.Parameters.Add("@ABRV", SqlDbType.VarChar)
        If SizeMeasureID = Nothing Then
            prm.Value = Me.SizeMeasureList.SelectedItem.Text
        Else
            prm.Value = SizeMeasureID
        End If
        sqlDR = cmd.ExecuteReader
 
        While sqlDR.Read
            SzMeasureID = sqlDR("SizeMeasureID")
        End While
 
        If sqlDR.HasRows Then
            CheckSizeMeasureID = SzMeasureID
        Else
            CheckSizeMeasureID = -1
        End If
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then
            If Not (sqlDR.IsClosed) Then
                sqlDR.Close()
            End If
        End If
        sqlDR = Nothing
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
        Return CheckSizeMeasureID
 
    End Function
    Private Function RetrieveSalesTPRItems()
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SGetSalesTPR", conn)
        Dim sqlDR As New SqlDataAdapter
        Dim ds As New DataSet
 
        Dim prm As New SqlParameter("@UserID", SqlDbType.VarChar, 50)
        cmd.CommandType = CommandType.StoredProcedure
        prm.Value = ReadCookie(Tokens.UserId)
        cmd.Parameters.Add(prm)
 
        conn.Open()
        sqlDR.SelectCommand = cmd
        sqlDR.Fill(ds)
 
        DataGrid1.DataSource = ds
        DataGrid1.DataBind()
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then sqlDR = Nothing
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
 
    End Function
    Public Sub DeleteItems(ByVal sender As Object, ByVal e As CommandEventArgs)
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SDeleteSalesTPRItem", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim sqlDR As SqlDataReader
 
        Dim p As New SqlParameter("@ItemID", SqlDbType.BigInt)
        p.Value = e.CommandArgument
        cmd.Parameters.Add(p)
 
        conn.Open()
        cmd.ExecuteNonQuery()
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then
            If (sqlDR.IsClosed) Then
                sqlDR.Close()
            End If
        End If
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
        RetrieveSalesTPRItems()
 
        With lblMessage
            lblMessage.Visible = True
            .CssClass = "labelGreen"
            .Text = "The Sale Item was successfully deleted ."
        End With
 
    End Sub
    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        DataGrid1.CurrentPageIndex = e.NewPageIndex
        RetrieveSalesTPRItems()
 
        With lblMessage
            lblMessage.Visible = True
            .CssClass = "labelGreen"
            .Text = "Page: " & DataGrid1.CurrentPageIndex + 1 & " of " & DataGrid1.PageCount.ToString
        End With
    End Sub
 
    Private Sub DoneButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DoneButton.Click
        Response.Redirect("MainMenu.aspx")
    End Sub
    Private Function VerifyUnicUPCCode(ByVal UPCCode As String) As Boolean
 
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SCheckUnicUPCforTPR", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim sqlDR As SqlDataReader
        Dim prm As SqlParameter
 
        conn.Open()
        sqlDR = cmd.ExecuteReader
 
        VerifyUnicUPCCode = True
 
        While sqlDR.Read
            If UPCCode = sqlDR("UPC") Then
                VerifyUnicUPCCode = False
                Exit While
            Else
                VerifyUnicUPCCode = True
            End If
        End While
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then
            If Not (sqlDR.IsClosed) Then
                sqlDR.Close()
            End If
        End If
        sqlDR = Nothing
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
        Return VerifyUnicUPCCode
 
    End Function
    Public Function VerifyStores() As Integer
        Dim i As Integer = 0
        Dim Count As Integer = 0
        Dim TempChain As Integer = -1
        Dim TempRegion As Integer = -1
        Dim TempCustomerLoyalty As Integer = -1
        Try
            For i = 0 To ListBox1.Items.Count - 1
                If ListBox1.Items(i).Selected Then
                    If Count = 0 Then
 
                        TempChain = GetChainNumber(ListBox1.Items(i).ToString)
                        TempRegion = GetRegionNumber(ListBox1.Items(i).ToString)
                        TempCustomerLoyalty = GetCustomerLoyaltyNumber(ListBox1.Items(i).ToString)
                        strselecteditems = ListBox1.Items(i).Text
                        Count = Count + 1
 
                    Else
                        If TempChain = GetChainNumber(ListBox1.Items(i).ToString) And TempRegion = GetRegionNumber(ListBox1.Items(i).ToString) And TempCustomerLoyalty = GetCustomerLoyaltyNumber(ListBox1.Items(i).ToString) Then
                            strselecteditems = strselecteditems & "," & ListBox1.Items(i).Text
                        Else
                            Return 0
                        End If
                    End If
                End If
            Next
            Return 1
        Catch ex As ApplicationException
 
        End Try
 
    End Function
    Public Sub ChangeItemStatus(ByVal sender As Object, ByVal e As CommandEventArgs)
        Dim conn As New SqlConnection(Application("A1SConnString"))
        Dim cmd As New SqlCommand("spA1SChangeTPRItemStatus", conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim sqlDR As SqlDataReader
 
        Dim p As New SqlParameter("@ItemID", SqlDbType.BigInt)
        p.Value = e.CommandArgument
        cmd.Parameters.Add(p)
 
        conn.Open()
        cmd.ExecuteNonQuery()
 
        'Clean Up
        If (Not sqlDR Is Nothing) Then
            If (sqlDR.IsClosed) Then
                sqlDR.Close()
            End If
        End If
        If (Not conn Is Nothing) Then
            If conn.State <> ConnectionState.Closed Then conn.Close()
            conn.Dispose()
        End If
        If Not cmd Is Nothing Then cmd.Dispose()
 
        RetrieveSalesTPRItems()
 
    End Sub
    
    Sub check_Load(ByVal Sender As Object, ByVal E As EventArgs) Handles MyBase.Load
 
        Dim DS As DataSet
        Dim MyConnection As SqlConnection
        Dim MyCommand As SqlDataAdapter
 
        MyConnection = New SqlConnection(Application("A1SConnString"))
        MyCommand = New SqlDataAdapter("select * from StoreTPR", MyConnection)
 
        DS = New DataSet
        MyCommand.Fill(DS, "Store")
 
        Mycheck.DataSource = DS.Tables("StoreTPR").DefaultView
        Mycheck.DataBind()
    End Sub
 
 
 
End Class

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 20420810
Ok I came to find out this may be the stored procedure So I ned to to do is declare the checkboxlist
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 20422432
We need to declare the checkboxlist1
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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