简体   繁体   中英

get header of a selected gridview column

I'm making a simple web application in C#. The site which I'm working on contains a GridView. The GridView shows the data from an Oracle SQL data table.

Now I want to have filtering options for my table. But I want to make it very easy to switch through the columns and I want to make it possible to filter and maybe sort each column for itself.

I already made a TextBox which instantly filters a specific column. But I want to have the User to select the column. My idea is to have the user selecting a column and then he only has to write his criteria into the TextBox.

My main problem at the moment is to figure out how to make the user able to select a column and get its index/header-text.

For instance: I want to get the index/header-text if the user wants to filter/sort the column and somehow selected it.

I'm new on asp.net and I don't really know how to realize this. I've searched a lot to find any solutions, but there isn't much about this.

I used this for my filtering method (works):

dt = GridView1.DataSource as DataTable;
dt.DefaultView.RowFilter = string.Format("Name LIKE '%{0}%'", textBox1.Text);
GridView1.DataSource = dt;
GridView1.DataBind();
  1. For sort by column specify inside the tag of the Gridview:

      AllowSorting="true">

  </asp:gridview>
  1. For Getting the header text of any column:

    Gridview.Columns[i].HeaderText

  2. No possible to filter by columns with a checkbox on the header

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM