本文介绍了数据源是无效类型。它必须是ilistource,notienume或idatasource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的api代码与实体框架..
this is my api code with entity framework..
public class UpdateHotelInfoesController : ApiController
{
private UpdateHotelInfoEntities db = new UpdateHotelInfoEntities();
// GET: api/UpdateHotelInfoes
public IQueryable<updatehotelinfo> GetUpdateHotelInfo()
{
return db.UpdateHotelInfo;
}
// GET: api/UpdateHotelInfoes/5
[ResponseType(typeof(UpdateHotelInfo))]
public IHttpActionResult GetUpdateHotelInfo(int id)
{
UpdateHotelInfo updateHotelInfo = db.UpdateHotelInfo.Find(id);
if (updateHotelInfo == null)
{
return NotFound();
}
return Ok(updateHotelInfo);
}
这是源代码
this is source code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged1">
<columns>
<asp:BoundField DataField="HOTEL_NAME" HeaderText="HOTEL_NAME" />
<asp:BoundField DataField="ADDRESS_LINE" HeaderText="ADDRESS_LINE" />
<asp:BoundField DataField="AREA" HeaderText="AREA" />
<asp:BoundField DataField="CITY" HeaderText="CITY" />
<asp:BoundField DataField="POSTAL_CODE" HeaderText="POSTAL_CODE" />
<asp:BoundField DataField="STATE" HeaderText="STATE" />
<asp:BoundField DataField="COUNTRY" HeaderText="COUNTRY" />
<asp:BoundField DataField="PHONE_NUMBER" HeaderText="PHONE_NUMBER" />
<asp:BoundField DataField="LANDLINE" HeaderText="LANDLINE" />
<asp:BoundField DataField="EMAIL_ID" HeaderText="EMAIL_ID" />
<asp:BoundField DataField="WEBSITE" HeaderText="WEBSITE" />
<asp:BoundField DataField="PROPERTY_TYPE" HeaderText="PROPERTY_TYPE" />
<asp:BoundField DataField="PROPERTY_GRADE" HeaderText="PROPERTY_GRADE" />
<asp:BoundField DataField="REGISTRATION" HeaderText="REGISTRATION" />
this is my c# code for displaying.it in grid view
protected async void Button4_Click(object sender, EventArgs e)
{
up.POSTAL_CODE = Convert.ToInt32(TextBox2.Text);
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(Base_URL);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
StringContent con = new StringContent(JsonConvert.SerializeObject(up), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.GetAsync("api/UpdateHotelInfoes/" + TextBox2.Text);
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
var data = await response.Content.ReadAsStringAsync();
var a = JsonConvert.DeserializeObject<mainobject>(data);
GridView1.DataSource = a;>>>..here am getting exception.
GridView1.DataBind();
}
anyone knows how to get rid of this issue?
What I have tried:
i tried using the above code .but its giving the exception <pre>Data source is an invalid type. It must be either an ilistsource, ienumerable, or idatasource?.
how to get rid of this?
推荐答案
GridView1.DataSource = new List<mainobject>{a};
这篇关于数据源是无效类型。它必须是ilistource,notienume或idatasource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!