Click here to Skip to main content
16,014,707 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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;



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>
Posted
Updated 14-May-17 1:19am
Comments
F-ES Sitecore 11-May-17 6:13am    
We don't have access to your data sources so how can we possibly know what the problem is? You'll need to use the debugger to step through your code and examine the variables and data to work out what is going wrong. Chances are "response.IsSuccessStatusCode" is false, which could be due to the url you are accessing.

"api/UpdateHotelInfoes"+TextBox2.Text

if TextBox2 has "Hello" then you are calling

api/UpdateHotelInfoesHello

which is probably wrong.
saimanisha 11-May-17 6:24am    
later i mentioned "/" but also its not working.
shreyal acharya 11-May-17 6:15am    
Check this link For your Problem

http://aspnettutorials.com/tutorials/database/add-data-to-gridview-from-multiple-tables-in-asp-net-4-0-and-c/
saimanisha 11-May-17 6:28am    
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 the api code using entity framework ..put delete and update methods are working but am unable display the data ..the request to api is working fine..but how can i display the respose into the gridview.
F-ES Sitecore 11-May-17 6:43am    
Your update method doesn't return data. If the update has succeeded then you need to call another method that returns the hotel data.

1 solution

Hi u need to add
GridView1.DataBind();

at the end of your code
 
Share this answer
 
v2
Comments
saimanisha 15-May-17 2:12am    
i added already , but also its not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900