如何在网格视图中添加按钮控件,其中在asp.net中自动生成列

问题描述:

嗨......

我想在网格视图中添加按钮控件,其中在asp.net中自动生成列.我正在尝试创建允许数据排序和过滤的网格用户控件,其中我将数据集绑定到自动生成列的网格中.我想添加小2标题中的按钮或图像用于向上和向下箭头进行排序.但是我无法这样做.为此提供解决方案以生成具有按asc和desc排序按钮的动态网格.thanx

hi......

How to add button control in grid view where columns generated automatic in asp.net.I am trying to create grid user control allow data sorting and filtering, in which i am binding dataset to grid where columns are autogenerated.I want to add small 2 buttons or images in header for up and down arrow for sorting.but i am not able to do.provide solution for this to generate dynamic grid with buttons to asc and desc sorting.thanx

可以说,您需要在gridView中对第二,第三和第四列进行排序...填充gridview之后,请执行以下操作.

Lets say, you need to sort 2nd 3rd and 4th column in your gridView... After you populate gridview do the following.

gridview.Columns.Clear();
gridview.DataSource = somedatasource;
gridview.AutoGenerateColumns = true;
if (this.gridview.Rows.Count > 0)
{
gridview.Columns[1].SortMode = gridview.Columns[2].SortMode =   gridview.Columns[3].SortMode = DataGridViewColumnSortMode.Automatic;
gridview.Sort(gridview.Columns[1], ListSortDirection.Ascending); //This will put a sort indicator on 2nd column on gridview, and obviously sorted too..
}