GridView,它必须是IListSource,IEnumerable或IDataSource?

时间:2017-05-19 10:32:32

标签: c# asp.net gridview

这是我的实体框架api代码 公共类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);
    }

c#c​​ode

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;
                     GridView1.DataBind();
                 }

gridview控件的源代码

<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" />
        </Columns>
    </asp:GridView>

为什么数据没有在gridview中显示,并且收到错误 gridview1.datasource = a;&gt;&gt;&gt;&gt; GridView,它必须是IListSource,IEnumerable或IDataSource

我必须做些什么来摆脱这个问题。任何人都知道如何摆脱这个。

0 个答案:

没有答案