473,748 Members | 7,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting DropDownList to a Default Value?????

I have a DropDown Lsit set to
ddlGetDebtor.It ems.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.Se lectedItem.Valu e))

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.Sql Client.SqlExcep tion: Error converting data type nvarchar
to int. at
System.Data.Sql Client.SqlComma nd.ExecuteReade r(CommandBehavi or
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
System.Data.Sql Client.SqlComma nd.ExecuteReade r() at
Online_Ordering .CheckOut.FillA ll(Object sender, EventArgs e) in
c:\inetpub\wwwr oot\Online_Orde ring\CheckOut.a spx.vb:line 209

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #1
4 4703
Hi Patrick

try the code below

private void dropdownlist_Se lectedIndexChan ged(object sender,
System.EventArg s e)
{

if( dropdownlist.Se lectedIndex > 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.Se lectedItem.Valu e.ToString))
--
There is always a way
"Patrick Olurotimi Ige" wrote:
I have a DropDown Lsit set to
ddlGetDebtor.It ems.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.Se lectedItem.Valu e))

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.Sql Client.SqlExcep tion: Error converting data type nvarchar
to int. at
System.Data.Sql Client.SqlComma nd.ExecuteReade r(CommandBehavi or
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
System.Data.Sql Client.SqlComma nd.ExecuteReade r() at
Online_Ordering .CheckOut.FillA ll(Object sender, EventArgs e) in
c:\inetpub\wwwr oot\Online_Orde ring\CheckOut.a spx.vb: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_Se lectedIndexChan ged(object sender,
System.EventArg s e)
{

if( dropdownlist.Se lectedIndex > 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.Se lectedItem.Valu e.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.Select edIndex > 0 Then
EndIf
Without affecting the "objDR.NextResu lt()"

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

MyConn.Open()
objDR = Cmd.ExecuteRead er

ddlFill1.DataSo urce = objDR
ddlFill1.DataVa lueField = "AddressID"
ddlFill1.DataTe xtField = "Suburb"
ddlFill1.DataBi nd()

objDR.NextResul t()


ddlFill2.DataSo urce = objDR
ddlFill2.DataVa lueField = "AddressID"
ddlFill2.DataTe xtField = "Suburb"
ddlFill2.DataBi nd()
'ddlFill2.Items .Insert(0, "-Select Delivey Address-")

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

objDR.NextResul t()

With ddlFill4
.DataSource = objDR
.DataValueField = "TelstraAcc ID"
.DataTextField = "TelstraAcc No"
.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
2273
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) private int GetMatchingIndexOfDropDown(ref DropDownList d, string MatchValue) { return }
0
1908
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 control. In a default.aspx page <SkinExample:Hello id="HelloControl" SkinName="red" runat="server" /> i can pass the value, it works fine, but from the dropdownlist in a codebehind page i can't pass the value. Could some one help me out with...
2
1750
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 match retrieved data. When I set the first, everything is fine. Then I set the second and the first gets set to the second index. Can you see anything wrong with this code? Thanks If DR.HasRows Then Do While DR.Read() Dim name As String =...
7
2040
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 time to allow me to have the first option in the list a ‘listitem’ saying something like ‘please pick an option’, and then the rest of options coming from the database. <asp:dropdownlist id="fm_Category" runat="server"...
2
11312
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 database. for example: if the ddl_value is 2 from the database i want the second list item to be selected by default.
9
2344
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 are set to the value of the last control. I found this link: http://www.codecomments.com/archive315-2005-1-366113.html which I think explains the situation but I'm not sure how to implement the solution in my case since I am not using a .ascx...
8
1673
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 as the dataReader can only be read once. I tried: ExperienceLevel.DataSource=dbReader ExperienceLevel.DataTextField= "Description"
2
7917
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 FormView's ObjectDataSource "odsRegistrant" . The following solution can't work because I need the ddl selected value bound to my odsRegistrant but both tables have the same column name for primary key. <asp:DropDownList ID="ddlOfficePark"...
1
1873
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 DropDownList is interpreting the default DateTime value as a string value "1/1/0001 12:00:00 AM". DateTime.Parse in turn converts that string value to #12:00:00 AM# with no date values. What am I doing wrong here? Here is some relevant code...
4
6140
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 extra item just doesn't get added to the DropDownList: ============================================= <script runat="server"> Sub Page_Load(..........) Dim dSet As DataSet Dim sqlConn As SqlConnection
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6796
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.