Welcome Guest ( Log In | Register )

Bump Topic Topic Closed RSS Feed

Outline · [ Standard ] · Linear+

 value is save in database but is not showing in dr

views
     
TSGneko86
post Apr 27 2015, 12:14 PM, updated 9y ago

Getting Started
**
Junior Member
71 posts

Joined: Jul 2011
need some assistance. I am currently learning vb.net with sql.

I have two textboxes (txtValue and txtText) , a dropdownlist (ddl1) and save button (btnAdd).
I insert value to txtValue and txtText (eg: txtValue: A and txtText: Apple).
when i click button Add, The value will display in dropdownlist (like this; A - Apple) and both data will be save in the sqlserver (db).

im having issue where when i click button Add, the data is not display in the dropdownlist. But when i refresh my browser, the data will display in dropdownlist.

ASP.net

CODE

        <asp:DropDownList ID="ddl1" runat="server" CssClass="form-control" AutoPostBack="true"></asp:DropDownList>
       
         <label class="form-control-static">Value</label>
         <asp:TextBox ID="txtValue" runat="server" CssClass="form-control"></asp:TextBox>
          <label class="form-control-static">Text</label>
          <asp:TextBox ID="txtText" runat="server" CssClass="form-control"></asp:TextBox>
                             
          <button id="btnAdd" runat="server" style="min-width: 80px;">Add</button>


VB.Net

CODE
  Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
   
           If Page.IsPostBack = False Then
   
               Dim rs As DataSet
   
   
               ddl1.Items.Clear()
               ddl1.Items.Add("")
               rs = db.ExecuteSelect("SELECT value, text FROM dropdownlist ", Session("CnnStr").ToString)
               For i = 0 To rs.Tables(0).Rows.Count - 1
   
                   ddl1.Items.Add(rs.Tables(0).Rows(i).Item("value").ToString & " - " & rs.Tables(0).Rows(i).Item("text").ToString)
   
               Next
           End If
       End Sub
   
   
     
       Protected Sub btnAdd_ServerClick(sender As Object, e As EventArgs) Handles btnAdd.ServerClick
           db.ExecuteInsert("INSERT INTO dropdownlist (value, text ) VALUES( " & _
                                "'" & db.sqlstr(txtValue.Text) & "'," & _
                               "'" & db.sqlstr(txtText.Text) & "') ", _
                                Session("CnnStr").ToString)
   
       End Sub



UDPATE : Already solved by myself. Just need to create a fuction for dropdownlist .

This post has been edited by Gneko86: Apr 27 2015, 12:23 PM

Topic ClosedOptions
 

Change to:
| Lo-Fi Version
0.0127sec    0.28    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 07:11 AM