views:

334

answers:

2

Here's the scenario: -Gridview control -Calendar control

I only want the calendar to show if a specific item is chosen in the drop down list which is in a gridview. When the grid view row is updated I want to change whether or not the calendar is visible. The calendar's visibility only shows correctly on the next post back.

A: 

Page_Load is called before events which are called before Render. There is no reason why you couldn't, in your event, check the value of the dropdownlist and set the Calendar control visible property, this would then knock into Render.

Tim
A: 

Try adding a check of IsPostBack before setting the loading your GridView. That will prevent you from overwriting it's values.

protected void Page_Load(object sender, EventArgs e) {
    if(!IsPostBack) {
         /*Populate your GridView*/
    }
}

protected void GridView_RowUpdated(object sender, GridViewUpdatedEventArgs e) 
{
    /*show your calendar here if you need to*/
    if(whatever) calendar.Visible = true;
}

This should work, if it doesn't then I'd recommend putting breakpoints in your Page_Load and RowUpdated methods and stepping through it, preferrably with a Watch on the gridview's datasource (it'll go red if it's changed) and a watch on calendar.Visible, to help you see if something has changed.

For the record, control events like OnRowUpdated will never fire before Page_Load unless explicitly called for some reason. Chances are you're just doing something where it's not updating the content of the GridView before it gets to the RowUpdated method, or it's overwriting the data in the GridView due to a lack of !IsPostBack check.

blesh
I change the calendar's visibility in the event handler for the gridview_rowupdated (I mistakenly put dropdownlist in my first description). And it doesn't show up until the next post back.
Well it seems like something is happening to the data before it gets to the section where it's updating the data in the grid view to something before it can check and see what was in there and set the calendar control to visible.
blesh