1

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"];
}
1
  • 2
    Not sure if this helps. But there is a method named "Select()" which returns an IEnumerable which you can use and iterate the collection. Commented Feb 12, 2015 at 11:07

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

I have to say that you are awesome! Superb answer and one I will definitely be reusing in the future I'm sure +1 :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.