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

  • Thread starter Thread starter Piotrek \Alchemik\
  • Start date Start date
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
 
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
 
Back
Top