Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
here's an example what i've came up so far. its pretty simple

http://img.iz.my/show.php/765_tnya.png.html[^]

i just bind the northwind database in a gridview (mind the data in that gridview is from multiple tables)

so what i want to do is some sort of quick data filtering using dropdownlist together with textbox (search)

how can i put the columns "Contact Name", "City" and "Country" in the dropdown? i don't want the records inside the dropdown like i did in the example
Posted
Updated 22-Apr-12 17:36pm
v3
Comments
Sergey Alexandrovich Kryukov 22-Apr-12 23:25pm    
How's that? all titles are the sale representatives? with the same phone? And do you think HomePhone should be written in one word in camel case? :-)
But seriously, why do you think this picture is helpful? How about code sample? And what's the question? What do you mean "how can I put"?
--SA
Izzat Zainol 22-Apr-12 23:34pm    
sorry, i've updated the screenshot with clearer picture what i meant exactly. basically the screenshot is my result what i've done not what i intended it to be

i don't want "Maria Anders" in the dropdown. but what i want instead is the title of the column

for example once the page is loaded the dropdown will be filled "Contact Name", "City" and "Country"

not the rows in contact name or city and country so on..

1 solution

Hi Check this Example will Guide you
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
            {
                con.Open();
                   //Change with your select statement .
                using (SqlCommand cmd = new SqlCommand("select * from test1", con))
                {
                    DataTable dt = new DataTable();
                    SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                    adpt.Fill(dt);
                    Dictionary<int,> lst = new Dictionary<int,>();
                    foreach (DataRow row in dt.Rows)
                    {
                        //Add values to Dictionary
                        string val = row[1].ToString() + " , " + row[2].ToString() + " , " + row[3].ToString();
                        lst.Add(Convert.ToInt32(row[0]), val);
                    }
                    DropDownList1.DataSource = lst;
                    DropDownList1.DataTextField = "Value";
                    DropDownList1.DataValueField = "Key";
                    DropDownList1.DataBind();
                }
            } 
        }
    }


ASP.NET
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>

Best Regards
M.Mitwalli
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900