Accessing a footer field in a template column, on a datagrid, with Master Pages

TheWizardofInt

Junior Contributor
Joined
Dec 31, 1969
Messages
333
Location
Orlando, FL
I have a site that uses a Master page

On that site, I have a page that uses a datagrid to take data entries

Part of the footer on the datagrid is a button that pops up a calendar. Clicking on the calendar causes a postback of the date selected to the page with the datagrid

All of that works

Now, I have the post back, and I have the date and I want to put it back into a text field, in the footer of the datgrid.

Using datagrid.item.findcontrol doesn't work because, of course, the footer isn't an item

I tried to do a javascript statement using clientside register script block, and it can't find the field by id. Yes, I am aware that the master page concatonates the id, and it is looking for the right id. I can do a ViewSource and find the altered textfield id

Anyone been down this rocky road before?
 
How about using the ItemDataBound method ...

//Set up a global variable for the Date
DateTime globalDate;


protected void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
((TextBox)e.Item.FindControl("txtDateValue")).Text = globalDate.ToString();

}
}

or something like that .... Of course you will need to bind your datagrid again, and make sure you are checking for IsPostBack so you won't bind twice .. If you have your datagrid binding on Page_Load this happens happens before the event that calls the postback so you will be binding it twice..

Or you can work your way through the rendered table hierarchy with FindControl .... What's always helpful to me is trace ... set trace=true on the page and it will show the rendered hierarchy ...

FYI on master pages .... The master page is rendered as a user control (well basically) .... So you will have to use the correct hierarchy when trying to find anything with the FindControl method ... So if you try and use Page.FindControl it needs to now be Master.FindControl("ContentAreaControlInMasterName").FinControl("") ....

That held me up a couple of hrs ... figure I would pass on the findings ..

hopefully this is not too late and it's help maybe a little .....
 
Back
Top