Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I am new to .net
I have a problem where when I debug my code, there is no value when trying to execute sql query. The value in cbContact.text is blank. cbContact is a dropdownlist where I already choose the selected value. I already did try change the property to .selectedvalue but still same. Appreciate on you guys advise. Please find my coding as below.

VB
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If txtprojectname.Text = "" Then
            cf.messagebox("Please key in Project Name !", Me)
            txtprojectname.Focus()
            Exit Sub
        End If

        Dim StrSQL As New StringBuilder

        If txtprojectname.Text <> "" Then
            StrSQL.Remove(0, StrSQL.Length)
            StrSQL.Append("INSERT INTO tblorderdetails(Customer,SSIStaff,PONumber,CONumber,ProjectName,DateOrderReceived) VALUES (")
            StrSQL.Append("'" + cbCustCode.Text + "'")
            StrSQL.Append(",'" + cbContact.Text + "'")
            StrSQL.Append(",'" + txtponum.Text + "'")
            StrSQL.Append(",'" + txtconum.Text + "'")
            StrSQL.Append(",'" + txtprojectname.Text + "'")
            If Not IsNothing(dpOrderReceive.SelectedValue) Then
                StrSQL.Append(",'" + Format(CDate(dpOrderReceive.SelectedValue), "yyyy-MM-dd") + "')")
            Else
                StrSQL.Append(",Null)")
            End If

            cf.runSQLComm(StrSQL.ToString)
            'cf.addLog(Session("LoginID").ToString.Trim, "Create " + i.ToString)
            cf.messagebox("Record created !", Me)
            Exit Sub
        Else
            Exit Sub
        End If
    End Sub


As for the cbContact here is the coding. I query the value from a table.

VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session.LCID = 2057

        Me.MaintainScrollPositionOnPostBack = True

        BindComboBoxList()

End Sub

Sub BindComboBoxList()
        tblData = cf.GetDataTable("Select ContactPerson from tblcontactperson Order by ContactPerson")
        cbContact.Items.Clear()
        cbContact.Items.Add("")
        For Each r As DataRow In tblData.Rows
            cbContact.Items.Add(r(0).ToString.Trim)
        Next
 End Sub
Posted

Article about it..
Why DropDownList SelectedValue Does Not Work Inside SelectedIndexChanged Event?[^]

make sure,if you are binding the Dropdown list in page load event then place it inside
C#
if(!IsPostBack)
{
//bind dropdown
}
 
Share this answer
 
You have to add your
VB
BindComboBoxList()


inside
VB
If not IsPostBack Then

BindComboBoxList()

End IF
 
Share this answer
 
v2
Comments
Nikolai.Kimi 27-Nov-14 1:07am    
Hi Samad,

Thanks it working. Silly me. :-)
Maciej Los 27-Nov-14 2:18am    
+5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900