Click here to Skip to main content
15,909,332 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "WebForm3.aspx/BindDatatable",
                data: "{}",
                dataType: "json",
                success: function (data) {
                    for (var i = 0; i < data.d.length; i++) {
                       $("#gvDetails").append("<table><tbody><tr><td>" + (data.d[i].Consumption) + "</td><td>" + (data.d[i].MeterTimestamp) + "</td></tr></tbody></table>");
                    }
                },
                error: function (result) {
                    alert("Error");
                }
            });
        });
    </script>

  <asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false">
        <HeaderStyle BackColor="#DC5807" Font-Bold="true" ForeColor="White" />

.cs code like
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;


namespace WaterMeter_Solution
{
    public partial class WebForm3 : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindColumnToGridview();
            }
        }
        /// <summary>
        /// This method is used to bind dummy row to gridview to bind data using JQuery
        /// </summary>
        private void BindColumnToGridview()
        {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[] { new DataColumn("Consumption"), new DataColumn("MeterTimestamp", typeof(DateTime)) });
            dt.Rows.Add();
            gvDetails.DataSource = dt;
            gvDetails.DataBind();
            gvDetails.Rows[0].Visible = false;
        }

        [WebMethod]
        public static UserDetails[] BindDatatable()
        {
            DateTime FromDate = DateTime.Today;
            DataTable dt = new DataTable();
            List<userdetails> details = new List<userdetails>();
            {
                using (OracleDataBase objdb = new OracleDataBase())
                {
                    dt = objdb.GetServiceWiseConsumption("PR_GET_RECORDS_PER_SERVICE", 6, FromDate);
                    foreach (DataRow dtrow in dt.Rows)
                    {
                        UserDetails user = new UserDetails();
                     //   user.UserId = dtrow["UserId"].ToString();
                        user.Consumption = dtrow["Consumption"].ToString();
                        user.MeterTimestamp = dtrow["MeterTimestamp"].ToString();
                        details.Add(user);
                    }
                }
            }
            return details.ToArray();
        }
        public class UserDetails
        {
            //public string UserId { get; set; }
            public string Consumption { get; set; }
            public string MeterTimestamp { get; set; }
        }

    }
}

like this am using in master page concept but it is not showing grid data in normal pages it is working fine y???
it is not showing can any one help me for this it s very urgent.
Posted
v2
Comments
See in the console window of FireBug in FireFox, if there are any errors.

Also it is a repost - jquery pop up window not displying gridview.

1 solution

On masterpage you cannot access control direct by id like :-
JavaScript
$("#gvDetails") 


you should use
JavaScript
$('#<%=gvDetails.ClientID %>')
instead of
JavaScript
$("#gvDetails")
 
Share this answer
 
v2
Comments
dasam 7-Jun-13 4:11am    
Thank you sir... its working fine... how to give paging option for this...please help me for this
Mohit_Rudra 11-Jun-13 0:24am    
look here :-
Pagination

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