locked
how to clear a textbox inside gridview in c sharp RRS feed

  • Question

  •  hi

             i am doing project in asp.net using c sharp .

    i am using a textbox inside gridview .after inserting the values in the gridview to the database

    i want to clear the textbox  values if anyone have any idea about how to clear a textbox inside

    gridview help me

                                 thanks in advance

                    

    • Moved by Mike Dos Zhang Thursday, May 31, 2012 9:06 AM (From:Visual C# General)
    Tuesday, May 29, 2012 7:57 AM

Answers

  • Use

    GridView1.EditIndex = -1; 

    If you are using AJAx with Jquey/Javascript please use Javascript or jQuery to clear the text box

    var grid = document.getElementById("<<Your Grid View Name>>”)
    for (i = 1; i < grid.rows.length; i++) 
    {
             cell = grid.rows[i].cells[0]
             for (j = 0; j < cell.childNodes.length; j++) 
              {
    	    if (cell.childNodes[j].type == "textbox") 
              {
    document.getElementById(cell.childNodes[j].id).value = “”;
    }
    }


    With Thanks and Regards Sambath Raj.C

    • Proposed as answer by Sambath Raj.C Wednesday, May 30, 2012 3:29 AM
    • Marked as answer by Mr. Wharty Tuesday, June 5, 2012 11:53 PM
    Wednesday, May 30, 2012 3:29 AM
  • Hi prabhakar78,

    You'll need to post it in the dedicated ASP.Net Forum http://forums.asp.net for more efficient responses, where you can contact ASP.NET experts.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Mr. Wharty Tuesday, June 5, 2012 11:53 PM
    Wednesday, May 30, 2012 3:29 AM

All replies

  • Hi Prabhakar,

     If you are using asp.net then why can't you use JQuery to clear all the textbox data to empty?

    I mean, please use jquery/javascript (what ever you are comfirtable) to clean textbox once saved to the database.

    If you want to clear all the textbox in your page use

    $('#form input[type=text]').val("");

    if you want to clear all textbox's in a gridview  use

    $('#<%= gridview1.ClientID %> input[type=text]').val("");

    Hope it will help you...


    Sai Kumar K (MCP)
    Blog: Sai's Stuff.
    WebSite: SantoshTechnologies.

    Tuesday, May 29, 2012 8:11 AM
  • The gridview should represent the data like it is in the database, therefore can you elaborate a little bit more/

    Success
    Cor

    Tuesday, May 29, 2012 9:39 AM
  • Use

    GridView1.EditIndex = -1; 

    If you are using AJAx with Jquey/Javascript please use Javascript or jQuery to clear the text box

    var grid = document.getElementById("<<Your Grid View Name>>”)
    for (i = 1; i < grid.rows.length; i++) 
    {
             cell = grid.rows[i].cells[0]
             for (j = 0; j < cell.childNodes.length; j++) 
              {
    	    if (cell.childNodes[j].type == "textbox") 
              {
    document.getElementById(cell.childNodes[j].id).value = “”;
    }
    }


    With Thanks and Regards Sambath Raj.C

    • Proposed as answer by Sambath Raj.C Wednesday, May 30, 2012 3:29 AM
    • Marked as answer by Mr. Wharty Tuesday, June 5, 2012 11:53 PM
    Wednesday, May 30, 2012 3:29 AM
  • Hi prabhakar78,

    You'll need to post it in the dedicated ASP.Net Forum http://forums.asp.net for more efficient responses, where you can contact ASP.NET experts.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Mr. Wharty Tuesday, June 5, 2012 11:53 PM
    Wednesday, May 30, 2012 3:29 AM