Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Error with dropdown list

Reply
Thread Tools

Error with dropdown list

 
 
JJ297
Guest
Posts: n/a
 
      01-08-2008
I have a dropdown list populated via a database. I edited the
dropdown list to have "select a topic" to always appear when the drop
down loads. Now if a user selects a dropdown item it goes into the
datagrid fine, but if a user selects "select a topic" I get an error
message...
Error converting nvarchar to int on adapter.Fill(ds)

Here's the code behind can someone please assist? Thanks!

Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DropDownList2.SelectedIndexChanged


Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager. ConnectionStrings("TrainUserConnectionString").Con nectionString)

Dim cmd As New Data.SqlClient.SqlCommand

With cmd
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "Getclassifications1"


If DropDownList2.SelectedValue = "select a topic" Then

Response.Write("Please select a topic")

Else
.Parameters.AddWithValue("classificationid",
DropDownList2.SelectedValue)
.Connection = conn
End If
End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmd)
Try

conn.Open()

Dim ds As New Data.DataSet
adapter.Fill(ds)

GridView1.DataSource = ds

GridView1.DataBind()

Finally

conn.Close()

End Try
 
Reply With Quote
 
 
 
 
smhusain1983@gmail.com
Guest
Posts: n/a
 
      01-08-2008
Hi,
I m a c# developer..dont have idea abt vb.net syntax but
the problem seems to be in If Condition..
seems like every time control passing in else condition n so passing
nvarchar value "select a topic" to ur procedure
which takes only int value for ID "classificationid" n so passing the
error messg..

just a guess..



On Jan 8, 8:30*pm, JJ297 <(E-Mail Removed)> wrote:
> I have a dropdown list populated via a database. *I edited the
> dropdown list to have "select a topic" to always appear when the drop
> down loads. *Now if a user selects a dropdown item it goes into the
> datagrid fine, but if a user selects "select a topic" *I get an error
> message...
> Error converting nvarchar to int on adapter.Fill(ds)
>
> Here's the code behind can someone please assist? *Thanks!
>
> * Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As
> Object, ByVal e As System.EventArgs) Handles
> DropDownList2.SelectedIndexChanged
>
> * * * * Dim conn As New
> Data.SqlClient.SqlConnection(ConfigurationManager. ConnectionStrings("TrainU*serConnectionString").Co nnectionString)
>
> * * * * Dim cmd As New Data.SqlClient.SqlCommand
>
> * * * * With cmd
> * * * * * * .CommandType = Data.CommandType.StoredProcedure
>
> * * * * * * .CommandText = "Getclassifications1"
>
> * * * * * * If DropDownList2.SelectedValue = "select a topic" Then
>
> * * * * * * * * Response.Write("Please select a topic")
>
> * * * * * * Else
> * * * * * * * * .Parameters.AddWithValue("classificationid",
> DropDownList2.SelectedValue)
> * * * * * * * * .Connection = conn
> * * * * * * End If
> * * * * End With
>
> * * * * Dim adapter As New Data.SqlClient.SqlDataAdapter(cmd)
> * * * * Try
>
> * * * * * * conn.Open()
>
> * * * * * * Dim ds As New Data.DataSet
> * * * * * * adapter.Fill(ds)
>
> * * * * * * GridView1.DataSource = ds
>
> * * * * * * GridView1.DataBind()
>
> * * * * Finally
>
> * * * * * * conn.Close()
>
> * * * * End Try


 
Reply With Quote
 
 
 
 
JJ297
Guest
Posts: n/a
 
      01-08-2008
On Jan 8, 11:53*am, (E-Mail Removed) wrote:
> Hi,
> I m a c# developer..dont have idea abt vb.net syntax but
> the problem seems to be in If Condition..
> seems like every time control passing in else condition n so passing
> nvarchar value "select a topic" to ur procedure
> which takes only int value for ID "classificationid" n so passing the
> error messg..
>
> just a guess..
>
> On Jan 8, 8:30*pm, JJ297 <(E-Mail Removed)> wrote:
>
>
>
> > I have a dropdown list populated via a database. *I edited the
> > dropdown list to have "select a topic" to always appear when the drop
> > down loads. *Now if a user selects a dropdown item it goes into the
> > datagrid fine, but if a user selects "select a topic" *I get an error
> > message...
> > Error converting nvarchar to int on adapter.Fill(ds)

>
> > Here's the code behind can someone please assist? *Thanks!

>
> > * Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As
> > Object, ByVal e As System.EventArgs) Handles
> > DropDownList2.SelectedIndexChanged

>
> > * * * * Dim conn As New
> > Data.SqlClient.SqlConnection(ConfigurationManager. ConnectionStrings("TrainU**serConnectionString").C onnectionString)

>
> > * * * * Dim cmd As New Data.SqlClient.SqlCommand

>
> > * * * * With cmd
> > * * * * * * .CommandType = Data.CommandType.StoredProcedure

>
> > * * * * * * .CommandText = "Getclassifications1"

>
> > * * * * * * If DropDownList2.SelectedValue = "select a topic" Then

>
> > * * * * * * * * Response.Write("Please select a topic")

>
> > * * * * * * Else
> > * * * * * * * * .Parameters.AddWithValue("classificationid",
> > DropDownList2.SelectedValue)
> > * * * * * * * * .Connection = conn
> > * * * * * * End If
> > * * * * End With

>
> > * * * * Dim adapter As New Data.SqlClient.SqlDataAdapter(cmd)
> > * * * * Try

>
> > * * * * * * conn.Open()

>
> > * * * * * * Dim ds As New Data.DataSet
> > * * * * * * adapter.Fill(ds)

>
> > * * * * * * GridView1.DataSource = ds

>
> > * * * * * * GridView1.DataBind()

>
> > * * * * Finally

>
> > * * * * * * conn.Close()

>
> > * * * * End Try- Hide quoted text -

>
> - Show quoted text -


Actually I solved it by adding List Item value = 0 on the asp page.
Then on the aspx page I added
If DropDownList2.SelectedItem.Value = "0" Then
DD2.Text = ("select a topic")
End If

It works!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
1 Gridview. Dropdown A is column from database, Dropdown B is column from database, Data in A and B must be from same row. anonymoushamster@gmail.com ASP .Net 2 11-07-2007 12:40 PM
ajax cascading dropdown: second dropdown disabled acadam ASP .Net 0 12-27-2006 10:59 AM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Select dropdown box bleeds into Javascript dropdown menu Mike HTML 1 12-18-2003 09:49 PM
Edit Mode - How do I populate dropdown in edittemplate from dropdown in another column? Steve Myers ASP .Net Datagrid Control 2 11-20-2003 01:09 PM



Advertisments