Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp:SqlDataSource绑定到asp:DropDownList_C#_Sqldatasource - Fatal编程技术网

C# asp:SqlDataSource绑定到asp:DropDownList

C# asp:SqlDataSource绑定到asp:DropDownList,c#,sqldatasource,C#,Sqldatasource,我的页面上有一个asp:SqlDataSource和asp:DropDownList组件。在正常页面上,它工作正常 现在我想把它放在新的页面上,url是…mypage.aspx?transactionID=2。在页面加载中,我想将事务下拉选择的索引设置为2。但它总是绑定到1。我假设事情按如下顺序发生:在页面加载中,我将selectedindex设置为2。然后执行asp:SqlDataSource的select语句并绑定到DropDownList。这就是为什么我的DropDownList的所选索引

我的页面上有一个asp:SqlDataSource和asp:DropDownList组件。在正常页面上,它工作正常

现在我想把它放在新的页面上,url是…mypage.aspx?transactionID=2。在页面加载中,我想将事务下拉选择的索引设置为2。但它总是绑定到1。我假设事情按如下顺序发生:在页面加载中,我将selectedindex设置为2。然后执行asp:SqlDataSource的select语句并绑定到DropDownList。这就是为什么我的DropDownList的所选索引总是1,不管我在Page\u Load中设置了什么


那么,如何将asp:SqlDataSource绑定到asp:DropDownList,并将其选定的索引参数设置为某个整数?

为DropDownList的OnDataBound事件编写事件处理程序,以在绑定后设置选定的索引

为DropDownList的OnDataBound事件编写事件处理程序,以在绑定后设置所选索引