I have a readymade library(dll) given to me, which has important data, i m able to take that data into Datatable and successfully displaying it on a GridView.
Now my further task is the Data what it is displaying in GridView should be filterable, meaning if i click on any column on a row it should filtered results of similar columns.
This is my GridView Result
HeaderCol1 HeaderCol2 HeaderCol3 HeaderCol4
Name1 Info1 ID1 Time1
Name2 Info2 ID2 Time2
Name1 Info3 ID3 Time3
Name3 Info2 ID4 Time4
Name4 Info4 ID3 Time5
Name5 Info5 ID5 Time5
Now what i want is if i click on Name1 it should show
HeaderCol1 HeaderCol2 HeaderCol3 HeaderCol4
Name1 Info1 ID1 Time1
Name1 Info3 ID3 Time3
And if i click on Info2 it should show
HeaderCol1 HeaderCol2 HeaderCol3 HeaderCol4
Name2 Info2 ID2 Time2
Name3 Info2 ID4 Time4
I think my question is clear now.
How can i achieve this?
Thanks in advance
So you want to filter a GridView’s
DataSourceby a value of a cell the user clicked on. These are multiple tasks in one, i’ll try to explain all.The major task is to enable that every cell in the
GridViewreacts on a user’s click, handling that click-event on serverside and get somehow the value from that cell.I’ve used a
DataTablein following example, replace it with your type of datasource. If you need to add custom events/controls toGridViewRowsthe best place isRowCreatedsince this is called on every postback not only on databinding. Note that you don’t have theDataItemat this stage.As you can see i’ve added the clientside
onclickevent to each cell. I’m using a hiddenTextBox(display:none) withAutoPostBack=trueto store the row and cell the user has clicked. Now you’re able to handle and process the click event on serverside.Here’s the aspx of my sample page: