I'm writing a custom server control (composite) in which one of the contained controls is a 'pageable' datagrid. I'm adding a custom templateColumn to the grid programmatically, which is a checkbox, a BoundColumn which displays a person's name and another BoundColumn, which is NOT visible that holds their unique Guid.
I want to display 5 names at a time, allow the user to select items via the checkboxes, page back and forth within the grid and still maintain the state of the checkboxes on returning to, let's say, a previously viewed datagrid page. To do this, I've tried two different methods: 1. I've registered the PageIndexChanged event within my server control to be handled by a method within the server control. eg. UserGrid.PageIndexChanged += new DataGridPageChangedEventHandler (DataGrid_PageChanged); private void DataGrid_PageChanged(object sender, DataGridPageChangedEventArgs e) { //A method that determines which people were selected and stores their information in a stateful property before changing the datagrid's pageindex and rebinding. DetermineSelectedMembers(); UserGrid.CurrentPageIndex = e.NewPageIndex; SetDataGridSettings(); UserGrid.DataBind(); } And in this method, after the DataBind() method call, I loop through the datagrid items (should be present since I just bound the data to it) and test one of my viewstate values for a person's guid and if they've been chosen before, check the checkbox. This doesn't work and it seems as if the PageIndexChanged event fires when I'm paging forward but not backwards?????? 2. The second thing I tried was just intercepting the ItemDataBound event of the datagrid and trying to check the value of the hidden cell containing the person's guid and comparing it with my maintained data source of guids that have been selected across postbacks. This would work great except that even though the datagrid pages display correctly, I'm getting text contents of " " returned to me in the method?????? private void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e) { sMembers = SelectedMembers.Split(new char[] {'|'}); foreach (string member in sMembers) { string memberGuid = e.Item.Cells[2].Text.ToString(); if (memberGuid == member) { //This is where I step through, test the value of memberGuid and get //" " and of course the data should be bound at this point, right? //The data does, in fact, display correctly in the browser CheckBox chk = new CheckBox(); chk = (CheckBox)e.Item.FindControl("SelectCheck"); chk.Checked = true; } } I've thought that since the Guid field is "hidden" there wouldn't be any "Text", so I tested this same code on a field that does display and I got the same result, " ". I'm stumped! Can somebody help me by shedding some light on this? Thanks much, Rachael You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.