RadGridView添加序号列

    public class RowNumberColumn : GridViewDataColumn
    {
        public override System.Windows.FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
        {
            TextBlock textBlock = cell.Content as TextBlock;

            if (textBlock == null)
            {
                textBlock = new TextBlock();
            }

            //textBlock.Text = (this.DataControl.Items.IndexOf(dataItem) + 1).ToString(); 
            textBlock.Text = ((this.DataControl.ItemsSource as IList).IndexOf(dataItem) + 1).ToString();

            return textBlock;
        }
    }
<telerik:RadGridView>
    <telerik:RadGridView.Columns>
        <local:RowNumberColumn Width="32" Header="序号"/>
     </telerik:RadGridView.Columns>
</telerik:RadGridView>

 

posted @ 2016-09-28 14:33  蘑菇mr  阅读(1210)  评论(0编辑  收藏  举报