How to compare DropDownList value and GridView column value, and hide if they are different?
I have 5 columns. In the first and in the second are values from DropdownList, and the others are results from some DMX query. I should hide the values in third column if they are not the same as the user select in DropDownList
I tried many solutions, but they do not work. Last, I tried this function. Thank you in advance!
private void GenerateUniqueData()
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
DataControlFieldCell cell = GridView1.Rows[i].Cells[2] as DataControlFieldCell;
if (cell.Text!=DropDownList6.SelectedItem.Value)
GridView1.Rows[i].Visible = false;
}
}
Take a look at this article. Too much to cover here:
http://www.codeproject.com/Articles/43727/Show-Hide-GridView-Columns-in-ASP-NET
Edit:
Let’s try it in plain ASP.NET with code behind:
First thing to check, did you switch on AutoPostBack on the DropDownList? If there is no round trip to the server none of your code makes any difference, it will not get executed.
Here’s a working example…
HTML:
Code Behind: