Handling server side click event of a button in a TemplateDataField doesn´t work with VirtualScrolling
Hello Alonso,
it's not clear enough what you are trying to achieve.
I attach a project with virtual scrolling enabled and a button inside a TemplateDataField in a WebDataGrid.
Can you please modify the sample, so that you reproduce the behavior you mean or send me your project? Looking forward to your answer.
Hi, thank you for your reply. The problem was that I had DataBind of Grid into WebDataGrid1_Init Event, not into load page.
Hi again.
I need to obtain the key of row pressed. I put the key value into CommandArgument. but after scrolling up and down and press button I obtain bad key.
I take your example. can you help me?
Code:
<asp:Button ID="Button1" CommandArgument='<%# Eval("key") %>' runat="server" Text="Button" OnClick="Button1_Click"/>
Button button = (Button)sender;
var key=button.CommandArgument;
Hello Alonso,In order to access the selected cell/row and the available event arguments, it will require to handle an appropriate event like CellSelectionChanged / RowSelectionChanged for example. They could be accessed on each PostBack, and if there is any selection, the selected cells / rows will be accessible.
Handling CellSelectionChanged: If, you need the cell's DataKey, that can be accessed using: WebDataGrid1.Behaviors.Selection.SelectedCells[0].Row.DataKey; or, alternatively using: e.CurrentSelectedCells[0].Row.DataKey;
Handling RowSelectionChanged:If, you need the row's DataKey: e.CurrentSelectedRows[0].DataKey; Please keep in mind that if you do not specify the DataKeys for the grid from the DataSource, the DataKeys are automatically generated.
If you want to get the Key of the selected cell's column you can access that by using: WebDataGrid1.Behaviors.Selection.SelectedCells[0].Column.Key or, if you are handling the CellSelectionChanged server-side event: e.CurrentSelectedCells[0].Column.Key
Please let me know how these suggestions work for you.
It is common practice to create a new forum thread with title - corresponding to the new issue, when the subject in the discussion changes from the original one. It is mainly because of tracking purposes. This helps finding similar issues more easily, when searching for previously posted threads in the forum.
Finally I decided handle the RowSelectionChanged event and put the dataKey into a Hidden Field . subsequently I get the correct data Key in server side. I don't think that it's a good solution, but it works. The UltraWebGrid control had CellClickButton event, very easy.
I am glad you found a working solution for the particular case discussed. Please let me know if you require further assistance regarding this matter.