Click here to Skip to main content
12,076,925 members (45,580 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB jQuery VB.NET
I want to bind column in girdview without postback how should i replace my old value from new value

<asp:GridView id="gridUserData" runat="server" />
                                <asp:TemplateField HeaderText="User Code" HeaderStyle-Width="110px" SortExpression="USRM_USER_CD"  >
                                        <asp:Label ID="lblRepUserCode" runat="server" Text='<%#Eval("USRM_USER_CD")%>' />
                                <asp:TemplateField HeaderText="User Name" SortExpression="USRM_USER_NAME" HeaderStyle-Width="150px">
                                        <asp:Label ID="lblRepUserName" runat="server" Text='<%#Eval("USRM_USER_NAME")%>' />
Public Shared Function GetProducts() As List(Of clsUSRM)
        Dim str As String = ""
        Dim table As DataTable = clsUSRM.ListData(str)
        Dim list As New List(Of clsUSRM)()
        For Each row As DataRow In table.Rows
            Dim detail As New clsUSRM()
            detail.USRM_USER_CD = (row("USRM_USER_CD")).ToString()
            detail.USRM_USER_NAME = row("USRM_USER_NAME").ToString()
        Return list
    End Function
function BindGridView() {
           type: "POST",
           url: "User_Create_Update.aspx/GetProducts",
           data: "{}",
           contentType: "application/json",
           dataType: "json",
           success: function (data) {
               for (var i = 0; i < data.d.length; i++) {
                 ("<tr><td>" + data.d[i].USRM_USER_CD +
                                           "</td><td>" + data.d[i].USRM_USER_NAME + "</td></tr>");
Posted 28-Feb-13 8:22am
Edited 28-Feb-13 11:24am
sayedfarhan 28-Feb-13 13:23pm
how to bind the data in grid
april88t 2-Mar-13 2:45am
how about trying this one----
>>>> click :
sayedfarhan 6-Mar-13 3:19am
this is ok when we have no pagination. when we have a pagination its hide the paginaiton and show all records in one page
sayedfarhan 6-Mar-13 3:18am
this is ok when we have no pagination.
when we have a pagination its hide the paginaiton and show all records in one page
agnesn88 13-Mar-13 3:05am
First step : Creating Data base which will be our data source ,we do it using building the following data table :


using System;
using System.Data;

public class DataStore
public DataStore()
// TODO: Add constructor logic here
public static DataTable GetDataTable()
DataTable dt = new DataTable("Names");
DataColumn dc1 = new DataColumn("Name");
DataColumn dc2 = new DataColumn("Age");
dt.Columns.AddRange(new DataColumn[] { dc1, dc2 });
DataRow dr1 = dt.NewRow();
dr1[0] = "Ahmed";
dr1[1] = "27";
DataRow dr2 = dt.NewRow();
dr2[0] = "Peter";
dr2[1] = "30";
DataRow dr3 = dt.NewRow();
dr3[0] = "John";
dr3[1] = "20";
DataRow dr4 = dt.NewRow();
dr4[0] = "Ali";
dr4[1] = "30";

return dt;

Next step:

Creating Class file "Names" which will contain two properties (Data base columns) for "FirstName" and "Age". Like this :

public class Names
public Names()
// TODO: Add constructor logic here
private string _firstName;
private string _age;
public string FirstName
set { _firstName = value; }
get { return _firstName; }
public string Age
set { _age = value; }
get { return _age; }

Next Step:

Creating default.aspx page which will display and call the data.
Create GridView Control in your page :

<br />
<asp:GridView ID="NamesGridView" runat="server" ShowHeaderWhenEmpty="True" >

<br />

Notice that we set ShowHeaderWhenEmpty property to true to display columns names when empty.

In page load event we will write some code which will display the gridview even it empty :

protected void Page_Load(object sender, EventArgs e)
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Name"), new DataColumn("Age") });
NamesGridView.DataSource = dt;
Notice that we created two columns Names as "Name" and "Age" .Now you can run the page the GridView should be displayed (try it!).

In code behind we will create a method which will connect to datastore and retrieve the data values. As the following :

public static Names[] GetNames()
List list = new List();
DataTable dt = DataStore.GetDataTable();
foreach (DataRow row in dt.Rows)
Names _names = new Names();
_names.FirstName = row["Name"].ToString();
_names.Age = row["age"].ToString();

return list.ToArray();

Here we fill data values in the two properties (FirstName,Age) then we add it to List which accept Names Class Object as you saw above. And at the end we need to convert it to an array .

Notice that the method decorated with [Web Method] attribute which will allow us to get this method using client side code , and the method need to be declared as public and static also to get reached outside the Container class .

Next Step :

- Calling Server side method that will get the data values and bind the gridview using Jquery like this :

<script type="text/javascript" src="">
<script type="text/javascript">
function BindGridView() {
type: "POST",
url: "Default.aspx/GetNames",
data: "{}",
contentType: "application/json",
dataType: "json",
success: function (data) {
for (var i = 0; i < data.d.length; i++) {
$("#NamesGridView").append("<tr><td>" + data.d[i].FirstName +
"</td><td>" + data.d[i].Age + "</td></tr>");

We can retrieve one column like "FirstName" or "Age" only, in the above code we create a loop to go through res
mohan.netdvplr 9-Jul-13 8:19am
alert(data.d.length); this is not returning any value...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.160212.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100