GridView footer controls - no default.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seanwalsh
    New Member
    • Mar 2008
    • 5

    #1

    GridView footer controls - no default.

    Hi

    I have a footer row in a gridview that allows inserting of records into a table. One of the controls is a DropDownList control. I want this control to default to the value in the QueryString. So I have this code:

    protected void Page_Load(objec t sender, EventArgs e)
    {
    DropDownList MenuInsert = gridviewPages.F ooterRow.FindCo ntrol("MenuInse rt") as DropDownList;
    MenuInsert.Sele ctedValue = Server.UrlDecod e(Request.Query String["Menu"]);
    }

    This works FINE when the page first loads. But then, when I add or edit or delete a row, i.e. after postback, the default does NOT get set.

    If I debug the code, at execution the code is picking up the correct control (checked the ClientID) and it runs the SelectedValue line, but when the page displays, it is not selected.

    Why not? The QueryString is still valid. I have in fact tested this on a TextBox in the Footer row, and I can't get a default to persist after postback there either. Any ideas? Something to do with VIEWSTATE?

    Thanks
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Try wrapping the code in your page_load method with a conditional statement checking for !IsPostBack

    Code:
     if(!IsPostBack) 
    {
    //your code here
    }
    Nathan

    Comment

    Working...