J
Joel Finkel
Folks,
I have a web application that displays rows from a database and, on each row, displays three ImageButtons, each of which needs to execute a different function. In order to improve performance, I have a Panel with a 26 buttons (labeled 'A' thru 'Z'), which is used to limit the rows to only those where the Name field begins with a specific letter (rather than returning the entire database each time).
The first time through, all those with the Name field beginning with 'A' are returned. When the user presses a different button, let's say 'F,' the application adjusts a parameter to the Stored Procedure, the sqlDataAdapter is filled, and, in order to display the data, the DataGrid does a DataBind.
So far so good. I can display only the subset of rows that I want. Neat. By the way, each of these 26 buttons runs client-side code that places the correct letter into an invisible text field and then submits the form, resulting in a postback.
Now for the problem with the ImageButtons: I placed these in a TemplateColumn and gave each of them a specific CommandName so that the event handler can figure out which function to call.
I created the function (ItemsGrid_Command), which swithes on CommandName to call the proper function. In the Page_Load function, I bind this handler to the DataGrid's ItemCommand delegate like this:
DataGrid1.ItemCommand += new DataGridCommandEventHandler(this.ItemsGrid_Command);
The problem is that this function never gets called; the page simply redisplays with the same data when I click on any of the three ImageButtons.
Having read that calling DataBind blows away the ItemCommand event handler, I confirmed that the event handler is called correctly if I do not do a DataBind (that is, if I test for IsPostBack). But I MUST perform the DataBind even if IsPostBack in order to display the new data subset. But then the ImageButtons do not function.
Interestingly, doing a DataBind does not destroy the ItemBound event handler. I attached code to this event to set the color of the rows depending on values in the row. So I know that it works. But it seems that the ItemCommand event is not re-created even though I always set it (see code, above).
I wonder if anyone has some suggestions for me as to how to achieve both of the required features: 1) limit the rows by first letter and 2) have three ImageButtons on each row that respond to user clicks.
Thanks,
Joel Finkel
(e-mail address removed)
I have a web application that displays rows from a database and, on each row, displays three ImageButtons, each of which needs to execute a different function. In order to improve performance, I have a Panel with a 26 buttons (labeled 'A' thru 'Z'), which is used to limit the rows to only those where the Name field begins with a specific letter (rather than returning the entire database each time).
The first time through, all those with the Name field beginning with 'A' are returned. When the user presses a different button, let's say 'F,' the application adjusts a parameter to the Stored Procedure, the sqlDataAdapter is filled, and, in order to display the data, the DataGrid does a DataBind.
So far so good. I can display only the subset of rows that I want. Neat. By the way, each of these 26 buttons runs client-side code that places the correct letter into an invisible text field and then submits the form, resulting in a postback.
Now for the problem with the ImageButtons: I placed these in a TemplateColumn and gave each of them a specific CommandName so that the event handler can figure out which function to call.
I created the function (ItemsGrid_Command), which swithes on CommandName to call the proper function. In the Page_Load function, I bind this handler to the DataGrid's ItemCommand delegate like this:
DataGrid1.ItemCommand += new DataGridCommandEventHandler(this.ItemsGrid_Command);
The problem is that this function never gets called; the page simply redisplays with the same data when I click on any of the three ImageButtons.
Having read that calling DataBind blows away the ItemCommand event handler, I confirmed that the event handler is called correctly if I do not do a DataBind (that is, if I test for IsPostBack). But I MUST perform the DataBind even if IsPostBack in order to display the new data subset. But then the ImageButtons do not function.
Interestingly, doing a DataBind does not destroy the ItemBound event handler. I attached code to this event to set the color of the rows depending on values in the row. So I know that it works. But it seems that the ItemCommand event is not re-created even though I always set it (see code, above).
I wonder if anyone has some suggestions for me as to how to achieve both of the required features: 1) limit the rows by first letter and 2) have three ImageButtons on each row that respond to user clicks.
Thanks,
Joel Finkel
(e-mail address removed)