Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am trying to get the value of the textbox of the selected row of the gridview

on the row command event of the gridview I have the following:

C#
TextBox txtAEditTimeDepart = (TextBox)Default._def.GRDTech.SelectedRow.FindControl("txtEditTimeDepart");


how ever it is returning me a null value and an error that it is not referring to anything.
Posted
Comments
ccalma 24-Apr-14 22:30pm    
Did you check the content of your SelectedRow? Also, you didn't access the .Text of the textbox.

1 solution

Try like this:
C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       try
       {
           if (e.CommandName == "Edit")
           {
               ImageButton img = (ImageButton)e.CommandSource as ImageButton;
               GridViewRow row = img.NamingContainer as GridViewRow;

               TextBox2.Text = ((Label)row.FindControl("txtEditTimeDepart")).Text;
           }

       }
       catch (Exception ex)
       {
           lblstatus.Text = "Error" + ex.ToString();
       }
   }
 
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