473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Setting DropDownList to a Default Value?????

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(Com mandBehavior
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.v b:line 209

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #1
4 4689
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
Nov 19 '05 #2
Try this:
Cmd.Parameters.Add(New SqlParameter("@DebtorCodeID",
ddlGetDebtor.SelectedItem.Value.ToString))
--
There is always a way
"Patrick Olurotimi Ige" wrote:
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(Com mandBehavior
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.v b:line 209

*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #3
Thx Mate

"charmis p varghese" wrote:
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

Nov 19 '05 #4
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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Earl Teigrob | last post by:
I want to write a function where I pass in a reference to a dropdownlist and a "match value" and have it returns the index of the dropdownlist item that matchs (or -1 if there is no match) ...
0
by: adam | last post by:
i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user control from dropdownlist. I have property in a...
2
by: David Austin via .NET 247 | last post by:
Hello, I hope this is where I should post this. I have a problem with this code that I can't figure out...seems to be a bug in the dropdownlist control. I am trying to set multiple dropdownlists to...
7
by: Lastie | last post by:
Hi all, I’ve got a ‘dropdownlist’ web control and I can add ‘listitem’ no problem. I can also bind data from an SQL database fine. My problem is that I want to do both at the same...
2
by: huzz | last post by:
How do i make a dropdownlist selected value based on the value i retrive from the database. Basically i have an edit page and like to display the default value in a dropdown list from the...
9
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all...
8
by: tshad | last post by:
Can you databind a dropdownlist to another dropdownlist? I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next...
2
by: Dabbler | last post by:
In my Registrant FormView I have a DropDownList which loads data from a secondary SqlDataSource "sdsOfficeParks". I need the user to select an office park but save the selected value in the...
1
by: Vagabond Software | last post by:
I'm using a DropDownList in an EditItemTemplate column. This DropDownList will only ever have two dates in it; Now and the default DateTime value (1/1/1900 12:00:00 AM). Somewhere, somehow, the...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.