Click here to Skip to main content
16,020,706 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi, I want to databind gridview as "datasource = null" in javascript. How to do this?
Posted
Updated 19-Apr-12 22:01pm
v5

Try this.

Code-behind

C#
protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        string script = String.Format("javascript:return DeleteGridView('{0}');", gvAttribute.ClientID);
        txtPercentage.Attributes.Add("onkeydown", script);
    }
}


Javascript
JavaScript
function DeleteGridView(grid_id) {
    var grid = document.getElementById(grid_id);
    if (grid.parentNode) {
        grid.parentNode.removeChild(elem);
    }
    return false;
}
 
Share this answer
 
Hi there..

As I think that you wanna clear your data using javascript.. Just have a look here.. http://weblogs.asp.net/ahmedmoosa/archive/2010/10/30/bind-gridview-using-jquery.aspx[^]
I hope this will help you.
All the best..
 
Share this answer
 
Comments
sjelen 20-Apr-12 7:16am    
This is not actually binding - just rendering a table on client side.
It will display the data, but sorting, paging or editing on GridView will not work this way.
Datagrid is rendered as a table. Do viewsource of any page with datagrid and see.

When you are making any change via Javascript, you are making it client side and thus you need to work at basic html level.

Try:
JavaScript
//EmptyHTMLText is whatever empty html based text you would like to set
document.getElementById("gvTest").outerHTML = EmptyHTMLText;
 
Share this answer
 

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