[c#] dropdownlist from database and value send as parameter

P

Piotrek \Alchemik\

Hello,

i have small problem - i have dropdownlist, which is populated from
database by stored procedure. I had autopostback attached to this list.
I'm using this as a parameter to another stored procedure. So, when i
was using asp:SqlDataSource and bind to him values from this
dropdownlist everything was ok. But when i'm doing this in code behind
using SqlCommand and trying to get value from this dropdownlist

sensor = Int32.Parse(DropDownList1.nSelectedValue) ;

I got error. I can't find anything usefull for this kind of behaviour.
I hope somebody can help me

Piotrek
 
M

Mark Rae

I got error. I can't find anything usefull for this kind of behaviour.
I hope somebody can help me

Nobody can help you if you don't say what the error is...
 
P

Piotrek \Alchemik\

Mark said:
Nobody can help you if you don't say what the error is...

The error is:
Input string was not in a correct format.

So i suppose i'm not getting int from dropdown list:

<asp:DropDownList ID="stateDropDownList" runat="server"
AutoPostBack="True" DataTextField="ID_sensor"
DataValueField="ID_sensor" visible = "False"
DataSourceID="SensorFromTestowa">
</asp:DropDownList>
<asp:SqlDataSource ID="SensorFromTestowa" runat="server"
ConnectionString="<%$ ConnectionStrings:testowaConnectionString %>"
SelectCommand="SelectSensor"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>

For sure this one works fine if i pass parameter to SqlDataSource, but
trying to parse them in code behind i got this error.

Hope this one helps

Piotrek
 

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,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top