Hey everybody,
I'm completely new to C# and ASP and got added to a pretty big project so I'm in a bit over my head and kind of intimidated/terrified. Note: This project uses VS 2003, .NET framework 1.1, not really sure about C# version. So we have DataGrid, no DataGridView.
I have a button that performs an operation on the currently selected row in a datagrid. The operation (new window, details, etc.) is already fully set up. My job comes in when the operation isn't performing on the currently selected row. It's always performing on the top row in the grid.
So this new window retrieves a datarow from cache. That's how the datarow is passed, but there was no event listener to cache the newly selected row. When the grid was loaded, the first row is cached and hence the first row always being retrieved. So I added a FocusedRowChanged listener that calls a CacheFocusedRow function (already written), which uses gridData.FocusedRow.KeyValue to get the row number and Cache.Insert this DataRow.
So the event listener wasn't firing, I figure out I need gridData.BehaviorOptions.PostBackOnFocusedRowChanged=true. Now it fires 3 times every time a row is clicked, but when I hit the magic button to do the operation, it retrieves the row that was selected last, not the newly selected row. This whole retrieval/cache process is bizarre to me but it's been around a long time and I assume it does it's job.
I'm a javascript/php guy. If this were in javascript I'd add a setTimeout or something to let the selection of the new row go through before getting the selected row. I have no idea what to do in C#.
So my questions to you brilliant folk if anyone would be so kind:
1) How can I retrieve the newly selected DataRow inside an event listener that fires on FocusedRowChange if the row doesn't actually change until after the listener is done? (I think) Should I be using something other than FocusedRow.KeyValue?
2) Why would my breakpoint at the start of the event listener be hit 3 times every time I change rows?
3) I tried to set the PostBackonFocusedRowChanged=true to the html for the Grid and got a server error saying behavior options doesn't have that. When I add it to C# at the end of Page_Load, no error. Something seems wrong about this.
Any help, suggestions, ideas would be extremely appreciated and you might just save my hide. Thanks very much. -Ed
Edit: Answer to 1) I really should've known this. You can't use grid.FocusedRow in an event listener be cause it would get the current row before the change. Derp. So i use RowEventArgs.Row.KeyValue and it gives me the new row. Sorry for the waste. The other two questions I'm still curious about.