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

    Display label value outside the Gridview textbox

    Hi,
    I have label value inside the Gridview ItemTemplate and i have a button inside the gridview
    my requirement is when i click the inside the gridview button, i want to display the label value to text box. But this textbox is outside the gridview.
    I tried but label value was not displayed in the textbox.
    Here i paste my code could anybody guide to me whats wrong in my code.

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
    GridViewRow gv = ((Button)sender).Parent.Parent as GridViewRow;
    Label lblTaskName = (Label)gv.FindControl("lblTaskName");
    string strTaskName = lblTaskName.Text.ToString();
    txtTask.Text = strTaskName ; // this TextBox is out side the gridview
    }

    I got the label value but value not displayed in the textbox

    thanks and regards
    brite
  • #763357
    Are you using updation using ajax(update panel) or normal postback.

    In the page load the textbox value will become blank. you have to handle the IsPostback in the page load.

    And also you can do this using some hidden fields also

    By Nathan
    Direction is important than speed

  • #763361
    Hello Brite,

    You can try this code :

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
    GridViewRow gv = ((Button)sender).Parent.Parent as GridViewRow;
    txtTask.Text = (gv.FindControl("lblTaskName") as Label).Text; // this TextBox is out side the gridview
    }

    Just try this code and let me know whether it satisfy your requirement or not.

    Hope this will be helpful for you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763368
    Hi,

    I guess the problem is the postback. When you assign label value to your textbox control value has been assigned but due to postback or reload the data may be again value empty is assign back to the control. I rewuest you to please debug the program and check the values.

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

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

  • #763422
    store the value in a session variable and after post back or in page load set this value.

    So even if the page is post back you will always have this value for text box.

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


Sign In to post your comments