17 February 2014

How to make DropDownList work with OnSelectedIndexChanged in ASP.net

Problem: Working with ASP.net , I got stuck working with dropdownlist . I chose the first item which would be copied to a textbox using onSelectedIndexChanged() . But it fails. How get the text value after clicking on dropdownlist on first click ?


Solution:
To do this,
change your sql query ( MS SQL Server 2005) to the following pattern :


SELECT '-Select Room-' AS Expr1
UNION ALL
SELECT DISTINCT [room] FROM [class_routine]

Note: If your data source is binded then this might not work . In this case , double click on the event "DataBinding" of the dropDownList.

and enter this code :

ddlSec.Items.Insert(0, "-Select Section-");

(If you found this article useful then share with your friends.)

No comments: