Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 26-Feb-13 2:26am
v3

1 solution

this can be done using CAML query..

XML
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";
            this.ddCompany.DataBind();


        }
        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>" +

                  "</Where>";

            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";
            this.ddDepartment.DataBind();

            //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)
        {

            PopulateDepartmentDropDown();


        }
 
Share this answer
 

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