Get second level headers RadGrid

0 Answers 16 Views
Ajax Grid
Alina
Top achievements
Rank 1
Alina asked on 12 Mar 2022, 08:37 AM | edited on 12 Mar 2022, 08:39 AM

Hi,

I'd like to dynamically change names of the second-level headers in RadGrid, but I've got no idea how to access to headers which are GridBoundColumn, not GridColumnGroup. When my grid have only GridBoundColumn headers there are no problem, but i've added GridColumnGroup and it stopped working. 

Could you help me to understand how to get headers of each level separately? Thanks!

 protected void RadGrid1_PreRender(object sender, EventArgs e)
            {   
                GridHeaderItem headerItem = STOCKTb.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;          
                Act = "select distinct Неделя_планир from REF_DATE where [Год-мес] = 202202 order by Неделя_планир";
                sqlCmd1 = new SqlCommand(Act, SqlConn);
                sqlDataAdap1 = new SqlDataAdapter(sqlCmd1);
                dtRecord1 = new DataTable();
                sqlDataAdap1.Fill(dtRecord1);
                if (dtRecord1.Rows.Count == 4)
                {
                    for (int i = 1; i < 5; i++)
                    {
                        headerItem[""+ i +""].Text = "Неделя " + Convert.ToString(dtRecord1.Rows[i-1][0]);
                        headerItem["1" + i + ""].Text = "Факт " + Convert.ToString(dtRecord1.Rows[i - 1][0]);
                    }
                }
                else if (dtRecord1.Rows.Count == 5)
                {
                    
                    for (int i = 1; i < 6; i++)
                    {
                        headerItem["" + i + ""].Text = "Неделя " + Convert.ToString(dtRecord1.Rows[i-1][0]);
                        headerItem["1" + i + ""].Text = "Факт " + Convert.ToString(dtRecord1.Rows[i - 1][0]);
                    }                    
                }              
            }

   <ColumnGroups>
                <telerik:GridColumnGroup HeaderText="Product Details" Name="21" HeaderStyle-HorizontalAlign="Center">
                </telerik:GridColumnGroup>
                <telerik:GridColumnGroup HeaderText="Location" Name="22">
                </telerik:GridColumnGroup>
                <telerik:GridColumnGroup HeaderText="Category" Name="23">
                </telerik:GridColumnGroup>
                <telerik:GridColumnGroup HeaderText="Order Details" Name="24" 
                    HeaderStyle-HorizontalAlign="Center">
                </telerik:GridColumnGroup>
                                    <telerik:GridColumnGroup HeaderText="Order Details" Name="25"
                    HeaderStyle-HorizontalAlign="Center">
                </telerik:GridColumnGroup>
            </ColumnGroups>
								<Columns>
									<telerik:GridBoundColumn DataField="Ассортимент_код"   HeaderText="Ассортиментная позиция">
										<ItemStyle Width="270px" />
									</telerik:GridBoundColumn>
									<telerik:GridBoundColumn Aggregate="Sum" DataField="1"   HeaderText="Неделя 9" ColumnGroupName="21" FooterText="Итого, кг: ">
										<ItemStyle Width="65px" />
									</telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn Aggregate="Sum" DataField="11"   HeaderText="Неделя 9" ColumnGroupName="21" FooterText="Итого, кг: ">
										<ItemStyle Width="65px" />
									</telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn Aggregate="Sum" DataField="2"   HeaderText="Неделя 10" ColumnGroupName="22" FooterText="Итого, кг: ">
										<ItemStyle Width="65px" />
									</telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn Aggregate="Sum" DataField="12"   HeaderText="Неделя 10" ColumnGroupName="22" FooterText="Итого, кг: ">
										<ItemStyle Width="65px" />
									</telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn Aggregate="Sum" DataField="3"   HeaderText="Неделя 11" ColumnGroupName="23" FooterText="Итого, кг: ">
										<ItemStyle Width="65px" />
									</telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn Aggregate="Sum" DataField="13"   HeaderText="Неделя 11" ColumnGroupName="23" FooterText="Итого, кг: ">
										<ItemStyle Width="65px" />
									</telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn Aggregate="Sum" DataField="4"   HeaderText="Неделя 12" ColumnGroupName="24" FooterText="Итого, кг: ">
										<ItemStyle Width="65px" />
									</telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn Aggregate="Sum" DataField="14"   HeaderText="Неделя 12" ColumnGroupName="24" FooterText="Итого, кг: ">
										<ItemStyle Width="65px" />
									</telerik:GridBoundColumn>
								</Columns>


 

No answers yet. Maybe you can help?

Tags
Ajax Grid
Asked by
Alina
Top achievements
Rank 1
Share this question
or