本文介绍了向Datagrid提供多个标题...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想显示一个从数据库到数据网格的表,但是我需要自定义数据网格标题.例如,如果一个表包含4个字段,如name1,name2,date1和date2,我需要添加在此字段上方的两个标头,如name和date.name1和name2应该位于name之下,date1和date2应该属于date.like这样,我需要自定义datagrid.我不知道该怎么做.帮我? .

i just want to display a table from database to a datagrid which i can do.but i need to customize the datagrid headers.like if a table consist of 4 fields like name1,name2,date1 and date2.i need to add two headers above this fields like name and date.name1 and name2 should come under name and date1 and date2 should come under date.like this way i need to customize the datagrid.i am not having any idea how to do it.can anyone pls help me? .

推荐答案

protected void Grid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Header)
    {
        DataGrid grid = sender as DataGrid;
        DataGridItem dgi = new DataGridItem(0, e.Item.DataSetIndex, ListItemType.Header);
        dgi.Cells.Add(new TableCell { ColumnSpan = 2, Text = "Name" });
        dgi.Cells.Add(new TableCell { ColumnSpan = 2, Text = "Date" });
        Table t = grid.Controls[0] as Table;
        t.Rows.AddAt(0, dgi);
    }
}


我不知道您的网格的确切布局,因此您可能必须添加更多单元以匹配您的设计.
如果使用自动生成的列,会有些复杂,但是原理是相同的.


I don''t know exact layout of your grid so you might have to add more cells to match your design.
It would be a bit more complicated if you use auto-generated columns, but the principle is the same.


这篇关于向Datagrid提供多个标题...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:57