I am trying to comsume a webservice which returns data by accepting parameters for method. The webservice has a class which returns data detailed in the class members.
I have made the reference to the webservice and trying to retreive the data in a detailview.
Error is as under:
Exception Details: System.InvalidOperationException: Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.
Source Error:
Line 26:
Line 27:
Line 28: DetailsView1.DataSource = bi.GetBooking((TextBox1.Text).ToString(), (TextBox2.Text).ToString());
Line 29:
Line 30: DetailsView1.DataBind();
Please advice how i could use IListSource, IEnumerable, or IDataSource with code.
Many thanks
Sanjay HarinathPosted Jul 10, 2007, 7:05 AM
Further to that is it possible to custom format the values of the heading column to my own Strings, i.e. I want to give the headings of the detailsview to be different to what is returned from the webservice as the present column headings are the xml tags. I would like to give proper names to them.
At the moment if i do something like this it changes the value of the data but not the heading.
resdirectbookinginfo.
Booking b = new resdirectbookinginfo.Booking();b = bi.GetBooking((TextBox1.Text).ToString(), (TextBox2.Text).ToString());
ArrayList al = new ArrayList();b.BookingDate =
"Booking Date"; // i want to be able to change b.bookingdate to "Booking Date" and not the value it is returning.b.BookingReference =
"Booking Reference"; // same hereal.Add(b);
DetailsView1.DataSource = al;
DetailsView1.DataBind();
Sanjay HarinathPosted Jul 10, 2007, 5:18 AM
It works fine with that. Thanks a lot.
I used the code as you suggested. Also added -
using
System.Collections;........button click event-----resdirectbookinginfo.
Booking b = new resdirectbookinginfo.Booking();b = bi.GetBooking((TextBox1.Text).ToString(), (TextBox2.Text).ToString());
ArrayList al = new ArrayList();al.Add(b);
DetailsView1.DataSource = al;
DetailsView1.DataBind();
AlanPosted Jul 9, 2007, 2:39 PM
An easy way to implement IEnumerable is to put the Booking object into an ArrayList. So, see if this will work:
Booking b = bi.GetBooking((TextBox1.Text).ToString(), (TextBox2.Text).ToString());
ArrayList al = new ArrayList();
al.Add(b);
DetailsView1.DataSource = al;
DetailsView1.DataBind();
Sanjay HarinathPosted Jul 9, 2007, 7:08 AM
class BookingHi Alan,
I have the following class defined. And the method is below where its loops through a counter and gets all the results.
public
{
[
XmlElement()] public string BookingReference;[
XmlElement()] public string StartDate;[
XmlElement()] public string DepartureDate;[
XmlElement()] public string BookingDate;[
XmlElement()] public string LeadName;[
XmlElement()] public string ConfirmationNo;[
XmlElement()] public string HotelName;[
XmlElement()] public string PropertyName;[
XmlElement()] public string Location;[
XmlElement()] public string City;[
XmlElement()] public string Travel;[
XmlElement()] public string RoomType;[
XmlElement()] public string NoOfRooms;[
XmlElement()] public string MealPlan;[
XmlElement()] public string Nights;[
XmlElement()] public string Adults;[
XmlElement()] public string Children;[
XmlElement()] public string AgentID;[
XmlElement()] public string HotelSupplier;[
XmlElement()] public string DistributorNet;[
XmlElement()] public string Total;[
XmlElement()] public string Error;[
XmlElement()] public string Transfer1Reference;[
XmlElement()] public string TransferSupplier;[
XmlElement()] ................and so on..}
the Method
cmd.Parameters.AddWithValue(
"@segnum", BookingRef);cmd.Parameters.AddWithValue(
"@user_id", Userid); SqlDataReader rdr = cmd.ExecuteReader();counter = 0;
while (rdr.Read()){
counter++;
if ((String)rdr["it_type"] == "hotel"){
b.BookingReference = (
String)rdr["segnum"];b.BookingDate = (
String)rdr["BookingDate"];b.StartDate = (
String)rdr["StartDate"];b.DepartureDate = (
String)rdr["DepartureDate"];b.LeadName = (
String)rdr["LeadName"];b.HotelName = (
String)rdr["HotelName"];b.Location = (
String)rdr["Location"];b.City = (
String)rdr["City"];b.ConfirmationNo = (
String)rdr["confirmationNumber"];b.Nights = rdr[
"Nights"].ToString();b.MealPlan = (
String)rdr["MealPlan"];b.RoomType = (
String)rdr["RoomType"];b.NoOfRooms = (
String)rdr["NoOfRooms"];b.Children = rdr[
"Children"].ToString();b.Adults = rdr[
"Adults"].ToString();b.AgentID = (
String)rdr["AgentID"];b.DistributorNet = rdr[
"DistributorNet"].ToString();b.Total = rdr[
"Total"].ToString();}
if ((String)rdr["it_type"] == "transfer" && (counter == 2)){
b.Transfer1Reference = (
String)rdr["Segnum"];b.Transfer1 = rdr[
"PropertyName"].ToString();b.Transfer1DistributorNet = rdr[
"DistributorNet"].ToString();b.Transfer1Total = rdr[
"Total"].ToString();b.TransferSupplier = (
String)rdr["SupplierID"];}
if ((String)rdr["it_type"] == "transfer" && (counter == 3)){
b.Transfer2Reference = (
String)rdr["Segnum"];b.Transfer2 = rdr[
"PropertyName"].ToString();b.Transfer2DistributorNet = rdr[
"DistributorNet"].ToString();b.Transfer2Total = rdr[
"Total"].ToString();}
}
return b;}
}
else{
b.Error =
"Please enter a valid Booking reference and Agent ID"; return b;}
}
AlanPosted Jul 6, 2007, 9:42 AM