Pages

Subscribe:

Ads 468x60px

Saturday, October 13, 2012

How to find the Previous Page Control's value on a current page in asp.net using c#

In this web Programming tutorial we will learn that how we can find or access a control like label, Dropdown, radiobutton, textbox etc from a previous page and its value to use in current page from gridview in asp.net using c#.
See the below code and just copy and paste the code and have fun.
  
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
     if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (!empty)
            {                
                Label lblcharges = e.Row.FindControl("lbl_charges") as Label;  
             }
         }  
   }

Control Function method .CS file of Current page to access the control's Value.

   private Control FindControl(string controlID, ControlCollection controls)
    {
        foreach (Control c in controls)
        {

            if (c.ID == controlID)

                return c;
            if (c.HasControls())
            {
                Control cTmp = this.FindControl(controlID, c.Controls);

                if (cTmp != null)

                    return cTmp;
            }

        }
        return null;
    }

  

No comments:

Post a Comment