如何通过`code-behind`获得`DataGridTextColumn`的名称和标题?

时间:2019-05-25 08:45:14

标签: c# asp.net datagrid datagridtextcolumn

我正在与datagrid一起工作,我想在后面的代码中获取datagridtextcolumn的名称和标题。

我尝试将标头值设为

`Datagrid.Columns[0].HeaderText` 

。但是HeaderText在我的代码中不起作用。

我尝试的另一种方法是

var HeaderTexts = dataGridUserSalesRep.Columns.Select(e => e.Header.ToString()).ToList();

这也不适合我。

我的Datagrid:

<DataGrid SelectionChanged="DatagridListviewSelectionChanged" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type Grid}, Mode=FindAncestor}}" Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type Grid}, Mode=FindAncestor}}"   x:Name="ListView"  Style="{StaticResource DataGridListing}"  >
                            <DataGrid.Columns>
                                <DataGridTemplateColumn  Width="0.5*"  >
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <RadioButton GroupName="RadioButtonGroup"   Style="{StaticResource DatagridRadioButton}"  IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTextColumn   Width="2*"  Header="{Binding SerialNo , Source={StaticResource Strings}}" x:Name="DataGridColumnSlNo"  Binding="{Binding SlNo}"   />
                                <DataGridTextColumn   Width="2*"  Header="{Binding ItemCode , Source={StaticResource Strings}}" x:Name="DataGridColumnHsn"  Binding="{Binding ItemCode}"   />
                                <DataGridTextColumn   Width="2*"  Header="{Binding itemName , Source={StaticResource Strings}}"   Binding="{Binding ItemName}"   />
                                <DataGridTextColumn   Width="2*"  Header="{Binding barcode , Source={StaticResource Strings}}"   Binding="{Binding BarCode}"   />
                                <DataGridTextColumn   Width="2*"  Header="{Binding hsnCode , Source={StaticResource Strings}}"   Binding="{Binding HsnCodes}"   />
                                <DataGridTextColumn   Width="2*"  Header="{Binding CountryOfOrigin , Source={StaticResource Strings}}"   Binding="{Binding COO}"   />
                                <DataGridTextColumn   Width="2*"  Header="{Binding Brand , Source={StaticResource Strings}}"   Binding="{Binding Brand}"   />
                                <DataGridTextColumn   Width="2*"  Header="{Binding shelf     , Source={StaticResource Strings}}"   Binding="{Binding Shelf}"   />
                            </DataGrid.Columns>
                        </DataGrid>

我想要这个数据网格的所有列的名称和标题

0 个答案:

没有答案