DataGrid in .NET 1.1 C#
-
I have a datagrid with with a button column and a few databound columns. The button column when clicked shows more details for a given row. ex) 123 ABC Company View Records 123 being a unique ID. ABC Company being a description. View Records is the button. When I added sorting to the headers, the application would direct me to the View Records code when clicking on the header to sort. I just wanted to sort. I found the reason. The InitializeComponent() was using an ItemCommand for the View Records button which is executed when any button on the grid is clicked. The headers for sorting were using the SortCommand for a datagrid. When I allowed sorting of the headers, I suspect .NET turned those headers into buttons. Is there anyway around this? I would like to keep my View Records button within the datagrid. I tried changing the View Records button into a hyperlink, but then I got an error for not having a correct datasource for the datagrid. I don't want to mess with the datasource select that is too much change.
-
I have a datagrid with with a button column and a few databound columns. The button column when clicked shows more details for a given row. ex) 123 ABC Company View Records 123 being a unique ID. ABC Company being a description. View Records is the button. When I added sorting to the headers, the application would direct me to the View Records code when clicking on the header to sort. I just wanted to sort. I found the reason. The InitializeComponent() was using an ItemCommand for the View Records button which is executed when any button on the grid is clicked. The headers for sorting were using the SortCommand for a datagrid. When I allowed sorting of the headers, I suspect .NET turned those headers into buttons. Is there anyway around this? I would like to keep my View Records button within the datagrid. I tried changing the View Records button into a hyperlink, but then I got an error for not having a correct datasource for the datagrid. I don't want to mess with the datasource select that is too much change.
In itemcommand event handler add a check on top if arguments.commandName != "sort". Moreover the button columns have the commandname property, so you can set different command name for buttons (if you have multiple buttons in one row) and in itemcommand event handler check the command name and act accordingly.
-----
-
In itemcommand event handler add a check on top if arguments.commandName != "sort". Moreover the button columns have the commandname property, so you can set different command name for buttons (if you have multiple buttons in one row) and in itemcommand event handler check the command name and act accordingly.
-----
Thanks. However, please bare with me. The headers sorting uses the SortCommand which has a different set of arguments, so I can't use the same itemcommand event handler. ex) ItemCommand Arguments (object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) SortCommand Arguments (object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) If I were to use ItemCommands arugments to do the if check, I would not have the correct SortCommand arguments to do a sort. If the sortcommand used the same parameters as the itemcommand, I could do the if statement because the sorted headers and buttons would all go to the same event handler.
-
Thanks. However, please bare with me. The headers sorting uses the SortCommand which has a different set of arguments, so I can't use the same itemcommand event handler. ex) ItemCommand Arguments (object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) SortCommand Arguments (object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) If I were to use ItemCommands arugments to do the if check, I would not have the correct SortCommand arguments to do a sort. If the sortcommand used the same parameters as the itemcommand, I could do the if statement because the sorted headers and buttons would all go to the same event handler.
Well surely you will use two event handlers. But if I remember I did face this problem in past, datagrid was firing the itemcommand on sort so I put a check on top in itemcommand event handler if e.commandname <> 'sort' and it worked fine. put a break point on sort and itemcommand event handlers and you will see that sort command is also going to itemcommand event handler.
-----