You must Sign In to post a response.
  • Category: ASP.NET

    How to get textbox value from a gridview control in a webpage programmed in asp.net 2.0 C#

    i am doing a forum
    in the forum i have texbox in gridview control in forum page
    how to get the textbox value in a string so as to check the same value with the DB
    i have tried like below but no use

    string Ques = (TextBox)GridViewFRM.Rows[i].Cells[0].FindControl("GVQuestionTextBox");
  • #730425
    Hi kumartyr,

    Which event you need to find that value. If you want in Load time then use RowDataBound event to find that contol

    Ex:

    protected void GV_OnRowDataBound(object sender,GridViewRowEventArgs e)
    {
    if(e.Row.RowType==DataControlRowState.DataRow)
    {
    //store textbox value into string
    string val=((TextBox)e.Row.FindControl("txtVal")).Text;
    }
    }


    If you are looking for any other place like button click time or something else then elaborate your question we provide solution for that. Finding controls is purely depending upon the action your trying to perform...

    Hope this will help you..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #730444
    If you are trying this when user hits some button of a GridView row, Then you need to write the code in RowCommand event of the GridView and then use the above code:

    //store textbox value into string variable string data=((TextBox)e.Row.FindControl("txtVal")).Text;

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #730448
    Hi,

    RowDataBound event in Gridview will be executed for each row that is binded from the database or from other datasource.

    So, you can check for rows/columns and controls inside the columns or rows and either you can set values to those controls or get values from those controls.

    protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    string strText = ((TextBox)e.Row.FindControl("txtProdName")).Text;
    }
    }

  • #730472
    thanks for your answers guys
    will let you know what worked for me

    thanks

  • #730497
    Modify your code as below.


    string Ques = ((TextBox)GridViewFRM.Rows[i].Cells[0].FindControl("GVQuestionTextBox")).ToString();


    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • Sign In to post your comments