简体   繁体   中英

ObjectDataSource in c# Code Behind?

Is it possible to read the data provided by an ObjectDataSource created in code behind? Take the following for instance:

ObjectDataSource myObjectDataSource= new ObjectDataSource();
myObjectDataSource.SelectParameters.Add(new SessionParameter("createdDate", TypeCode.String, "FilterCreated"));

How could you then get the rows from this? For example in a Dataset you would do something like:

foreach (DataRow dr in myDataset.Tables[0].Rows) {
     string abc = dr["myColumn"];
}

you can try like this , convert objectdatasource to dataset and than read that

private DataSet ConvertObjectSourceToDataSet(ObjectDataSource ods)
{
   var ds = new DataSet();
   var dv = (DataView)ods.Select();
   if (dv != null && dv.Count > 0)
   {
     var dt = dv.ToTable();
     ds.Tables.Add(dt);
   }
  return ds;
}

Code source : http://www.aspdotnet-suresh.com/2010/09/how-to-bind-dataset-with.html

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM