Quantcast
Channel: AjaxControlToolkit Work Item Rss Feed
Viewing all articles
Browse latest Browse all 4356

Commented Unassigned: Problem With ajaxtoolkit:combobox c# [27997]

$
0
0
hello guys :

I have combobox (typeco) witch it's bounded with table (type) .. and another combobox (modcom) bounded with table (model) ... when I choose the type , all models are changing the value of (modcom) by (typeco) ... this is not my problem .... my problem is : when I try to write not exist item it give me error directly ... i need to add items through a button but it shows this error ... i've try try catch and didn't work .... try add error in global.asax and it redirect me into other page ... but I want to add this new item via button at the same page !! ... I can't disable autopostback ....
note : typeco and modcom bounded to sqlconnection by GUI configuration
![Image](http://s2.postimg.org/85mylauvt/12289720_1059046990792505_6680867424156682626_n.jpg)
![Image](http://s13.postimg.org/rmxupuzp3/11205576_1059047077459163_1001913649223359416_n.jpg)
Comments: AJAX Control Toolkit ComboBox is derived from the [ListControl](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol(v=vs.110).aspx) class, which has the [Text](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.text(v=vs.110).aspx) property. However, the _Text_ property is just a wrapper of the [SelectedValue](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue(v=vs.110).aspx) property. This is why you see the integer value when getting the _Text_ property value of the _ComboBox_. The error shown in the screenshot you provided occurs because of ControlParameter for SqlDataSource "brandSqlDataSource1". This parameter has the Int32 datatype, so when you try to enter a new value into the "Devicecombobox" ComboBox, it always tries to convert Devicecombobox.SelectedValue to a number, but SelectedValue is a string. You can work around this issue by performing the following steps: 1. Remove the Type attribute from asp:ControlParameter. 2. Add the OnSelecting handler to brandSqlDataSource1. This handler will check the datatype of Devicecombobox.SelectedValue and run a SQL query only if this value is a number. Here is some sample code for this handler: ``` protected void brandSqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { if (e.Command.Parameters[0].Value != null) { string data = e.Command.Parameters[0].Value.ToString(); int machineID = 0; if (!Int32.TryParse(data, out machineID)) { e.Cancel = true; } } } ``` I attached the AjaxComboBoxtestUpd.zip archive, which contains an updated version of your test project with the changes described above.

Viewing all articles
Browse latest Browse all 4356

Trending Articles