Setting DropDownList to a Default Value?????

  • Thread starter Patrick Olurotimi Ige
  • Start date
P

Patrick Olurotimi Ige

I have a DropDown Lsit set to
ddlGetDebtor.Items.Insert(0, "-Select Debtor Code-")
which is setting the "-Select Debtor Code-" to be default

And on PostBack i'm passng:-
Cmd.Parameters.Add(New SqlParameter("@DebtorCodeID",
ddlGetDebtor.SelectedItem.Value))

to to retrieve the Data

DebtorCodeID is an integer
But when somebody selects a Value and does a Postback and gets back to
"Select Debtor Code" and select it it RETURNS an error!:-

System.Data.SqlClient.SqlException: Error converting data type nvarchar
to int. at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
System.Data.SqlClient.SqlCommand.ExecuteReader() at
Online_Ordering.CheckOut.FillAll(Object sender, EventArgs e) in
c:\inetpub\wwwroot\Online_Ordering\CheckOut.aspx.vb:line 209
 
C

charmis p varghese

Hi Patrick

try the code below

private void dropdownlist_SelectedIndexChanged(object sender,
System.EventArgs e)
{

if( dropdownlist.SelectedIndex > 0 )
{
//Do the database operation only when the selectedindex is greater than
0
}

}


regards
charmis
 
P

Patrick Olurotimi Ige

Hi DevGuy thx for the reply but using:-
Cmd.Parameters.Add(New SqlParameter("@DebtorCodeID",
ddlGetDebtor.SelectedItem.Value.ToString))

Still give the same error!!!

Whereas Charmis advice is good but in my case i'm using
NextResults() like so below:-

How should i use the

If DropDown.SelectedIndex > 0 Then
EndIf


Without affecting the "objDR.NextResult()"



Code Below:--
------------------
Try

MyConn.Open()


objDR = Cmd.ExecuteReader

ddlFill1.DataSource = objDR
ddlFill1.DataValueField = "AddressID"
ddlFill1.DataTextField = "Suburb"
ddlFill1.DataBind()

objDR.NextResult()




ddlFill2.DataSource = objDR
ddlFill2.DataValueField = "AddressID"
ddlFill2.DataTextField = "Suburb"
ddlFill2.DataBind()
'ddlFill2.Items.Insert(0, "-Select Delivey Address-")

objDR.NextResult()


With ddlFill3
.DataSource = objDR
.DataValueField = "AddressID"
.DataTextField = "Suburb"
.DataBind()
'ddlFill3.Items.Insert(0, "-Select Billing Address-")
End With

objDR.NextResult()

With ddlFill4
.DataSource = objDR
.DataValueField = "TelstraAccID"
.DataTextField = "TelstraAccNo"
.DataBind()
End With

ddlFill1.Items.Insert(0, "-Select Site Address-")
ddlFill2.Items.Insert(0, "-Select Delivey Address-")
ddlFill3.Items.Insert(0, "-Select Billing Address-")



Catch ex As SqlException
Response.Write(ex.ToString)
Finally

If Not (objDR Is Nothing) Then
objDR.Close()

End If

MyConn.Dispose()
End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top