Pages

Monday, July 15, 2013

Find the gridview control on button click event



Here , We will find the Value of the Label "lbl_ItemID" on Click event of Button1.

(all controls are in the gridview)


protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            Button Btn= (Button)sender;
            GridViewRow row = (GridViewRow)Btn.NamingContainer;        // find row
            Label ItemId = (Label)row.FindControl("lbl_ItemID");


            Response.Redirect("AddWatch.aspx?itemId=" + ItemId.Text, false);  // use value like this
        }
        catch (Exception ex)
        {
        }
    }

 

No comments:

Post a Comment