DataGrid控件-添加标题分页显示

None.gif          private   void  dgDoubleHeader_ItemCreated( object  sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
//获取DataGrid控件中项的类型
InBlock.gif
            ListItemType ItemType = e.Item.ItemType;
InBlock.gif            
//判断是否是页导航项
InBlock.gif
            if (ItemType == ListItemType.Pager) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
//判断是否是第一个页导航项
InBlock.gif
                if (upPager) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    
//根据DataGrid控件的项定义单元格对象
InBlock.gif
                    TableCell cellPersonal = (TableCell) e.Item.Controls[0];
InBlock.gif                    
//移出该单元格内的所有控件
InBlock.gif
                    cellPersonal.Controls.Clear();
InBlock.gif                    
//设置单元格对象的背景色
InBlock.gif
                    cellPersonal.BackColor = Color.Orange; 
InBlock.gif                    
//设置单元格对象的前景色
InBlock.gif
                    cellPersonal.ForeColor = Color.Black; 
InBlock.gif                    
//设置该单元格对象跨3列
InBlock.gif
                    cellPersonal.ColumnSpan = 2
InBlock.gif                    
//设置该单元格对象的对齐方式为居中
InBlock.gif
                    cellPersonal.HorizontalAlign = HorizontalAlign.Center; 
InBlock.gif                    
//添加单元格内的文本内容
InBlock.gif
                    cellPersonal.Controls.Add(new LiteralControl("姓名")); 
InBlock.gif                    
//定义单元格对象
InBlock.gif
                    TableCell cellWork = new TableCell();
InBlock.gif                    
//设置单元格对象的背景色
InBlock.gif
                    cellWork.BackColor = Color.OrangeRed;
InBlock.gif                    
//设置单元格对象的前景色
InBlock.gif
                    cellWork.ForeColor = Color.Black;
InBlock.gif                    
//设置该单元格对象跨2列
InBlock.gif
                    cellWork.ColumnSpan = 3
InBlock.gif                    
//设置该单元格对象的对齐方式为居中
InBlock.gif
                    cellWork.HorizontalAlign = HorizontalAlign.Center;
InBlock.gif                    
//添加单元格内的文本内容
InBlock.gif
                    cellWork.Controls.Add(new LiteralControl("联系方式"));
InBlock.gif                    
//在该项的控件集合中添加单元格对象
InBlock.gif
                    e.Item.Controls.Add(cellWork);
InBlock.gif                    
//改变Pager标志
InBlock.gif
                    upPager = false
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedBlockEnd.gif        }

None.gif
None.gif        
private   void  dgDoubleHeader_PageIndexChanged( object  source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
//改变Pager标志的值使其可以在每次触发分页事件时都设置标题头
InBlock.gif
            upPager = true
InBlock.gif            
//设置新的页面索引值
InBlock.gif
            dgDoubleHeader.CurrentPageIndex = e.NewPageIndex;
InBlock.gif            
//重新进行数据绑定
InBlock.gif
            DataGridDataBind();
ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/mjgforever/archive/2006/02/17/332692.html

要修改DataGrid控件的默认分页样式,可以使用自定义样式和模板。以下是一个示例,展示如何将分页按钮放置在DataGrid控件上方: ```xml <Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <Style x:Key="DataGridStyle" TargetType="{x:Type DataGrid}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGrid}"> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True"> <DockPanel> <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="5"> <Button Content="First" Command="{x:Static DataGridCommands.SelectFirstPage}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" /> <Button Content="Prev" Command="{x:Static DataGridCommands.SelectPreviousPage}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" /> <TextBlock Text="{Binding DisplayTo}" Margin="5" VerticalAlignment="Center" /> <Button Content="Next" Command="{x:Static DataGridCommands.SelectNextPage}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" /> <Button Content="Last" Command="{x:Static DataGridCommands.SelectLastPage}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" /> </StackPanel> <ScrollViewer x:Name="DG_ScrollViewer" Focusable="false"> <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> </ScrollViewer> </DockPanel> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <DataGrid Style="{StaticResource DataGridStyle}" /> </Grid> </Window> ``` 在此示例中,我们创建了一个名为DataGridStyle的自定义样式,并将其应用于DataGrid控件。该样式的模板使用DockPanel将分页按钮放置在DataGrid控件的顶部,并使用ScrollViewer包装ItemsPresenter以实现滚动。 您还可以根据需要更改分页按钮的样式和位置,以满足您的具体需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值