如何使用httpclient在webform中的gridview中显示数据? [英] How can I display data in the gridview in webform with httpclient ?

查看:90
本文介绍了如何使用httpclient在webform中的gridview中显示数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网格视图在浏览器中不可见的问题。并观察用于在gridview中显示数据的c#代码我需要做什么来修改数据。



我尝试过:



the problem the grid view is not visible in the browser.and observe the c# code for displaying data in gridview what are the modifications i have to do to dsiplay the data.

What I have tried:

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);

           if (response.IsSuccessStatusCode)
           {
               string data = await response.Content.ReadAsStringAsync();
              //var  A= JsonConvert.DeserializeObject<UpdateHotelInfo>(data);
               // List<UpdateHotelInfo> a = response.Content.ReadAsAsync<List<UpdateHotelInfo>>().Result;
               var result = JsonConvert.DeserializeObject<List<UpdateHotelInfo>>(data);
               GridView1.DataSource = result;







以下是aspx代码








below is aspx code


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
           <AlternatingRowStyle BackColor="White" />
           <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>
           <FooterStyle BackColor="#CCCC99" />
           <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
           <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
           <RowStyle BackColor="#F7F7DE" />
           <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
           <SortedAscendingCellStyle BackColor="#FBFBF2" />
           <SortedAscendingHeaderStyle BackColor="#848384" />
           <SortedDescendingCellStyle BackColor="#EAEAD3" />
           <SortedDescendingHeaderStyle BackColor="#575357" />
       </asp:GridView>

推荐答案


u需要添加

Hi u need to add
GridView1.DataBind();


代码末尾的


at the end of your code


这篇关于如何使用httpclient在webform中的gridview中显示数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆