I have a webform with a sqldatasource
that populates a DropDownList
. The webform's Page_Load
reads from that DropDownList
.
It seems that the values are not present in the DropDownList
when Page_Load
executes; DropDownList.Items.Count
equals 0 during Page_Load.
So when exactly is the dropdown populated? I know I can populate it in the codebehind, but I prefer using sqldatasource
.
Thanks.
This MSDN link helped me out.
At Page_Load
, the SqlDataSource
control hasn't been bound. Just call DropDownList.DataBind()
before I access the control.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.