Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9178283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:30:56+00:00 2026-06-17T17:30:56+00:00

How to compare DropDownList value and GridView column value, and hide if they are

  • 0

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;
    }

} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:30:57+00:00Added an answer on June 17, 2026 at 5:30 pm

    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.

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
    </asp:DropDownList>
    

    Here’s a working example…
    HTML:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataGridTest.aspx.cs" Inherits="DataGridTest" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
                onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            </asp:DropDownList>
            <br />
            <br />
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>
        </div>
        </form>
    </body>
    </html>
    

    Code Behind:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    
    public partial class DataGridTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<string> ddData = new List<string>();
                ddData.Add("Col 21");
                ddData.Add("Col 22");
                ddData.Add("Col 23");
    
                this.DropDownList1.DataSource = ddData;
                this.DropDownList1.DataBind();
    
                DataTable gridData = new DataTable();
                gridData.Columns.Add("Description");
                gridData.Columns.Add("Column 1");
                gridData.Columns.Add("Column 2");
                gridData.Columns.Add("Column 3");
    
                gridData.Rows.Add("Row 1", "Col 11", "Col 21", "Col 31");
                gridData.Rows.Add("Row 2", "Col 12", "Col 22", "Col 32");
                gridData.Rows.Add("Row 3", "Col 13", "Col 23", "Col 33");
                gridData.Rows.Add("Row 3", "Col 14", "Col 22", "Col 34");
    
                this.GridView1.DataSource = gridData;
                this.GridView1.DataBind();
            }
        }
    
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                this.GridView1.Rows[i].Visible = true;
    
                string cellvalue = GridView1.Rows[i].Cells[2].Text;
                if (cellvalue.TrimEnd() != this.DropDownList1.SelectedItem.Value.TrimEnd())
                    GridView1.Rows[i].Visible = false;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare a date against the first of next month from
I am trying to compare values of a particular column between 2 csv. I
I need to compare and get the matching values from a string list with
I m new here and in HTML.Well I have to select many values from
Is it possible to compare the attribute value in jQuery? example if( $(this).[ attribute
i have a dropdownlist (asp.net control) and a listbox control and a Add button
i want to compare some similar images to find that one, which have a
I would like to compare the values of the elements under a node fetched
I'm trying to compare 2 different char in assembly(calling assembly function in C program).
I have the following on my website. Source [DropDownList] Website Search Engine Other Other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.