Results 1 to 2 of 2

Thread: Dynamic Form Objects [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member johnweidauer's Avatar
    Join Date
    Sep 2002
    Location
    SLC, UT
    Posts
    314

    Dynamic Form Objects [RESOLVED]

    I have a form, i want to use the DBReader to build out a list of items with a textbox to use as the quantity for each item. When the client clicks the Add Product button, I want to insert the information into a database, but i am not familiar with the form controls.

    Code:
    DBCmd = New OleDbCommand("EXEC sel_ProductInformation '" & Request.QueryString("FSKU") & "'",DBConn2)
        
             DBReader = DBCmd.ExecuteReader
        
             Response.Write("<Table width=700>" & vbCrlf)
        
             While DBReader.Read
                  Response.write("<TR>" & vbCrlf)
                  Response.write("<TD>" & DBReader("ProdSKU") & "</TD>" & vbCrlf)
                  Response.write("<TD>" & DBReader("Itmdesc1") & "</TD>" & vbCrlf)
                  Response.write("<TD>" & FormatCurrency(DBReader("MarkUp")) & "</TD>" & vbCrlf)
                  Response.write("<TD><input type=""text"" MaxLength=""4"" id=""Qty" & DBReader("ProdSKU") & """ size=""4"" /></TD>" & vbCrlf)
                  Response.write("</TR>" & vbCrlf)
        
             End While
        
             Response.write("</TABLE>" & vbCrlf)
    on the Sub Button1_Click(Sender As Object, E As EventArgs) event (Submit), I want to read the values of the textboxes on the form, however, with the way that I have written this page I do not know how to obtain the values. Any help?..maybe i have approached this in the wrong way.

    Thanks.
    Last edited by johnweidauer; May 20th, 2004 at 11:45 AM.

  2. #2

    Thread Starter
    Hyperactive Member johnweidauer's Avatar
    Join Date
    Sep 2002
    Location
    SLC, UT
    Posts
    314

    Solution

    Some of it is redundant, but it just made it easier to read for some

    Code:
    Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    
             If Not IsPostBack Then
    
                '// some stuff then
    
                 WriteSKUs()
    
             End If
    
        End Sub
    
    
    Sub WriteSKUs()
    
             Dim DBConn2 as OleDbConnection
             Dim DBCmd As OleDbCommand
             Dim DBReader As OleDbDataReader
             Dim NewTxtBx as TextBox
             Dim NewLbl1 as Label
             Dim NewLbl2 as Label
             Dim NewLbl3 as Label
             Dim NewLbl4 as Label
             Dim tRow As New TableRow()
             Dim tCell1 As New TableCell()
             Dim tCell2 As New TableCell()
             Dim tCell3 As New TableCell()
             Dim tCell4 As New TableCell()
             Dim NTable as New Table()
             Dim SubBtn as Button
             Dim Hyper as HyperLink
             Dim LblSpacer as Label
             Dim QtyVal as RangeValidator
    
             DBConn2 = New OleDbConnection("Provider=sqloledb;" _
                                              & "server=xxx;" _
                                              & "Initial Catalog=xxx;" _
                                              & "User Id=xxx;" _
                                              & "Password=xxx")
    
             DBConn2.Open()
    
             DBCmd = New OleDbCommand("SELECT * FROM XXX"'",DBConn2)
    
             DBReader = DBCmd.ExecuteReader
    
             Page.FindControl("AddProds").Controls.Add(NTable)
    
             NTable.Attributes.Add("Width","700px")
             NewLbl1 = New Label()
             NewLbl1.ID = "SKUHead"
             NewLbl1.Text = "<strong>SKU</strong>"
    
             NewLbl2 = New Label()
             NewLbl2.ID = "DescHead"
             NewLbl2.Text = "<strong>Description</strong>"
    
             NewLbl3 = New Label()
             NewLbl3.ID = "PriceHead"
             NewLbl3.Text = "<strong>Price</strong>"
    
             NewLbl4 = New Label()
             NewLbl4.ID = "QtyHead"
             NewLbl4.Text = "<strong>Quantity</strong>"
    
             tCell1.Controls.Add(NewLbl1)
             tCell2.Controls.Add(NewLbl2)
             tCell3.Controls.Add(NewLbl3)
             tCell4.Controls.Add(NewLbl4)
             tCell4.Attributes.Add("align","center")
    
             tRow.Cells.Add(tCell1)
             tRow.Cells.Add(tCell2)
             tRow.Cells.Add(tCell3)
             tRow.Cells.Add(tCell4)
    
             NTable.Rows.Add(tRow)
    
             While DBReader.Read
    
                    tRow = New TableRow()
                    tCell1 = New TableCell()
                    tCell2 = New TableCell()
                    tCell3 = New TableCell()
                    tCell4 = New TableCell()
    
                    NewLbl1 = New Label()
                    NewLbl1.ID = DBReader("ProdSKU")
                    NewLbl1.Text = DBReader("ProdSKU") & " &nbsp;&nbsp;&nbsp;"
    
                    NewLbl2 = New Label()
                    NewLbl2.ID = DBReader("Itmdesc1")
                    NewLbl2.Text = DBReader("Itmdesc1") & " &nbsp;&nbsp;&nbsp;"
    
                    NewLbl3 = New Label()
                    NewLbl3.ID = CStr(DBReader("ProdSKU") & DBReader("MarkUp"))
                    NewLbl3.Text = CStr(FormatCurrency(DBReader("MarkUp"))) & " &nbsp;&nbsp;&nbsp;"
    
                    NewTxtBx = New TextBox()
                    NewTxtBx.ID = "Qty" & DBReader("ProdSKU")
                    NewTxtBx.Attributes.Add("size","3")
                    NewTxtBx.Attributes.Add("maxlength","2")
    
                    tCell1.Controls.Add(NewLbl1)
                    tCell2.Controls.Add(NewLbl2)
                    tCell3.Controls.Add(NewLbl3)
                    tCell4.Controls.Add(NewTxtBx)
                    tCell4.Attributes.Add("align","center")
    
                    tRow.Cells.Add(tCell1)
                    tRow.Cells.Add(tCell2)
                    tRow.Cells.Add(tCell3)
                    tRow.Cells.Add(tCell4)
    
                    NTable.Rows.Add(tRow)
    
             End While
    
             LblSpacer = New Label()
             LblSpacer.ID = "LBR"
             LblSpacer.Text = "<BR/><BR/>"
             Page.FindControl("AddProds").Controls.Add(LblSpacer)
    
             SubBtn = New Button()
             SubBtn.ID = "SubmitProduct"
             SubBtn.Text = "  Add item(s) to your Shopping Cart  "
             SubBtn.Attributes.Add("runat","server")
             Page.FindControl("AddProds").Controls.Add(SubBtn)
    
             LblSpacer = New Label()
             LblSpacer.ID = "LSP"
             LblSpacer.Text = "&nbsp;&nbsp;&nbsp;"
             Page.FindControl("AddProds").Controls.Add(LblSpacer)
    
             Hyper = New HyperLink()
             Hyper.ID = "GoBAck"
             Hyper.NavigateURL = "javascript:history.back(-1);"
             Hyper.Text = " << Back "
             Page.FindControl("AddProds").Controls.Add(Hyper)
    
    
        End Sub
    
    <form id="AddProds" runat="server"></form>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width