Using the selected items in Sqldatasource
How can I use the results开发者_如何学编程 of the select method in SqlDatasource like assign the returned id to a variable ?
By default the SqlDataSource returns a System.Data.DataView object from its select method:
System.Web.UI.WebControls.SqlDataSource source = new System.Web.UI.WebControls.SqlDataSource("Connection String", "Select Query");
System.Data.DataView view = (System.Data.DataView)source.Select(System.Web.UI.DataSourceSelectArguments.Empty);
The System.Data.DataView object is a collection of System.Data.DataRowView so if you wanted to get the value of "pk" column for the first object you do this:
int itemIndex = 0;
String ColumnName = "pk";
int ID = view[itemIndex][ColumnName];
精彩评论