Click here to Skip to main content
13,458,661 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have created one list..inside that I placed one drop down..Depending on the option selected I need to show/hide the another colummn
Is it possible in SharePoint Web part?
Posted 25-Feb-13 23:51pm
Updated 26-Feb-13 2:26am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

this can be done using CAML query..

public  void PopulateCompanyDropDown()
            SPSite Site = new SPSite("http://xss-422:8000/default.aspx");
            SPWeb web = Site.OpenWeb();
            SPList SourceList1 = web.Lists["Company"];

            this.ddCompany.DataSource = SourceList1.Items.GetDataTable();
            this.ddCompany.DataTextField = "Title";
            this.ddCompany.DataValueField = "ID";

        public  void PopulateDepartmentDropDown()
            SPSite Site = new SPSite("http://xss-422:8000/default.aspx");
            SPWeb Web = Site.OpenWeb();

            SPList SourceList2 = Web.Lists["Department Name"];

            //foreach (SPListItem item in SourceList2.Items)

            //    Console.WriteLine(item.Title.ToString());
            //    Console.WriteLine(item.Fields[9].ToString());

            string caml = "<Where>" +

                      "<Eq>" +
                          "<FieldRef Name='{0}'/>" +
                          "<Value Type=\"Lookup\">{1}</Value>" +
                      "</Eq>" +


            SPQuery query = new SPQuery();
            string CompanyName = ddCompany.SelectedItem.Text.ToString();
            query.Query = string.Format(caml, "Company_x0020_Name", CompanyName);

            SPListItemCollection results = SourceList2.GetItems(query);

            this.ddDepartment.DataSource = results.GetDataTable();
            this.ddDepartment.DataTextField = "Title";
            this.ddDepartment.DataValueField = "ID";

            //txtManager.Text = SourceList2.Items[2]["Manager"].ToString();
            //txtUserName.Text = SourceList2.Items[2]["UserName"].ToString();
            //txtAddress.Text = SourceList2.Items[2]["UserComment"].ToString();

            //DataTable dtttt = results.
            //txtAddress.Text = SourceList2.Fields["UserComment"].ToString();

            DataTable dtttt = results.GetDataTable();


  protected void ddCompany_SelectedIndexChanged(object sender, EventArgs e)



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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04-2016 | 2.8.180323.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100