Hi everybody, I'm wandering if someone can help me with the following problem.
I have scenario where there is multiple grids on the page. Selection on one grid repopulates other grids. Every grid has template column with button for drill down functionality. Button column template is part of the grid and bound columns are created dynamically in the code behind. Because columns could be different, in code behind all columns except button are removed and recreated. Ajax is disabled on all grids. At first pass it works correctly and grid hits both Selection and ItemCommand events. on the second click on image button I'm getting error that FindControl requires unique id's. In the page source view I'm not able to find duplicates.
Hello Bane,
Thank you for contacting Infragistics! We received your support request concerning dynamic button template and firing of the item command event, and this case has been assigned to me. Infragistics is dedicated to helping you solve this issue. Our team and I have done an initial review of your case and I am looking into this matter and will get back to you by the end of the day Tuesday with more information or questions for you.
Sincerely,
Mike P.
Developer Support Engineer
Infragistics, Inc.
www.infragistics.com
Thank you for your patience. I have done some looking into this matter and I have a few questions concerning this matter. Are you clearing your datasource between rebinding of data to the gird? If so how are you doing this? How are you clearing and recreating the columns? How do you have the button template and template column setup? What properties are you using with the gird? Do you have EnableDataViewState enabled? What version of NetAdvantage are you using?
Hi Mike, first of all thanks for the prompt response. Please find my answers below.
Q:Are you clearing your datasource between rebinding of data to the gird? If so how are you doing this? Yes. Data source is cleared before rebinding. Please disregard commented code.
Friend Sub PopulateDetailGrid(ByVal stGrids As WebDataGrid, ByVal intGridIndex As Integer, ByVal intPage As Integer)
With stGrids
.ClearDataSource()
If .Columns.Count > 1 Then For i = .Columns.Count - 1 To 1 Step -1 .Columns.RemoveAt(i) Next End If
Dim dt As DataTable = Create_Data_Table()
For i = 0 To dt.Columns.Count - 1 .Columns.Add(Get_Bound_Grid_Column(dt.Columns(i).ColumnName)) .Columns(i).Width = Unit.Pixel(100) Next
dt.PrimaryKey = New DataColumn() {dt.Columns("Key")}
.DataSource = dt .DataBind() '.RequestFullAsyncRender()
'Populate paging listbox if required 'If Not stGrids.objGrid.Behaviors.Paging Is Nothing Then ' If stGrids.objGrid.Behaviors.Paging.Enabled Then ' Dim list1 As DropDownList = DirectCast(stGrids.objGrid.Behaviors.Paging.PagerTemplateContainerBottom.FindControl("DropDownList1"), DropDownList)
' list1.Items.Clear()
' For i = 1 To stGrids.objGrid.Behaviors.Paging.PageCount ' list1.Items.Add(i.ToString()) ' Next ' list1.SelectedIndex = intPage ' .Behaviors.Paging.PageIndex = intPage ' End If 'End If
'Set Time Grid Active Row 'If Not Session("gbooAnalysisLoaded") Then ' If .ClientID = "grdTime" Then ' Dim sel_rows_TimeGrid As SelectedRowCollection = stGrids.objGrid.Behaviors.Selection.SelectedRows ' With stGrids.objGrid ' For i = 0 To .Rows.Count - 1 ' 'If .Rows(i).Items(0).Value = cboTimeMember.SelectedItem.Text Then ' ' 'If .Rows(i).Cells(0).Value = cboTimeMember.SelectedItem.Text Then ' ' '.Rows(i).Activate() ' ' sel_rows_TimeGrid.Add(grdTime.Rows(i)) ' ' Exit For ' ' '.Behaviors.Activation.ActiveCell = .Rows(i).Items(1) ' 'End If ' Next ' End With ' End If 'End If
End With End Sub
Q: How are you clearing and recreating the columns? Please check on the above code. After clearing data source, I'm removing all columns except template field that is defined in the markup and then looping through data table to add bound columns.
Q: How do you have the button template and template column setup? In this case it is defined in markup as per grid definition below. Data view state is enabled
<ig:WebDataGrid ID="grd1" runat="server" Height="225px" Width="100%" AutoGenerateColumns="False" EnableDataViewState="True" EnableAjax="False"> <Columns> <ig:TemplateDataField Key="TemplateField_0"> <ItemTemplate> <asp:ImageButton ID="DrillUp" runat="server" OnClick="DrillUp_Click" ImageUrl="resources/arrow_down.png" Width="20px" CommandName="cmd_ddb_grd1" CommandArgument='<%# Eval("KEY") %>' /> </ItemTemplate> </ig:TemplateDataField> </Columns> <Behaviors> <ig:Activation> </ig:Activation> <ig:Paging PageSize="100"> <PagerTemplate> <asp:DropDownList ID="DropDownList1" runat="server" onchange="return IndexChanged(2)"> </asp:DropDownList> </PagerTemplate> </ig:Paging> <ig:Sorting> </ig:Sorting> <ig:Selection CellClickAction="Row" RowSelectType="Multiple"> <SelectionClientEvents RowSelectionChanged="grd_AfterSelectChangeHandler" /> <AutoPostBackFlags RowSelectionChanged="True" /> </ig:Selection> </Behaviors> </ig:WebDataGrid>
What version of NetAdvantage are you using? Version=12.1.20121.1005
In fact I expected that you would need more information so I've prepared sample solution for you to review, so please find it in the attachment.
Let me give you some more description of what I am trying to achieve. Page contains multiple grids that are filled with data from the SSAS cube. There are detail and total grid with data sources as tables that are populated from respective MDX. Selection on one grid filters data on other grids, so all grids are getting populated on each post back. Detail grid rows have drill down button and total grids have drill-down and drill-up buttons. We have the application running on controls version 11.1 and WebGrid and we are trying to upgrade to 12.1 and WebDataGrid. On the running application we used cellButtons and it is working as designed, cell button click fired only its own event. Now with new controls buttons have to be recreated every time page loads so we created procedure to create template columns, but what happens is that we are getting RowSelectionChanged event fired but not ItemCommand. Comparing to running application we would need only ItemCommand to fire.
In the sample I'm attaching you can also find the module that handles button creation and template class. Since I could not get it to work I moved buttons to markup.
This problem holds me for weeks already and I would greatly appreciate any input on it.
Thanks in advance,
Bane
Thank you for the update. I have started going over the sample you have provided and have the following information. Since you are creating and rebinding your data to the grid on every postback you should have EnableDataViewState set to false. This eliminates the first error with the duplicate id’s. After this I ran into another error when clicking the button, after some looking into this matter the second error seems to be related to the way you re-create your columns on postback when I modify your application to only create the columns on the initial load this error no longer occurs.
The following documentation contains information on setting up the columns of the grid both the bound and template columns.
http://help.infragistics.com/Help/NetAdvantage/ASPNET/2012.1/CLR4.0/html/WebDataGrid_Add_or_Remove_a_Column.html
http://help.infragistics.com/NetAdvantage/ASPNET/2012.1/CLR4.0/?page=WebDataGrid_Using_Item_Template.html
I will continue looking into this matter to see if I can get the columns setup so they can be created on every postback for you since you intend to change the columns that are being displayed. I will give you a progress update concerning this matter by the end of the day Tuesday.
Sincerely,Mike P.Developer Support EngineerInfragistics, Inc.www.infragistics.com
Thank you for your patience. I have modified your sample to demonstrate this behavior. To get this work I made a few changes first I Have EnableDataViewState set to false, your page load is not the PreInit and in the Get_Bound_Grid_Column I set the column to be tracked in viewstate to false.
Please let me know if you have any questions concerning this matter.