Click here to Skip to main content
12,503,334 members (64,499 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SharePoint
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
spunnam951
Updated 26-Feb-13 2:26am
v3

1 solution

Rate this: bad
 
good
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";
            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();
 

        }
  Permalink  

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 | Mobile
Web01 | 2.8.160919.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2016
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