Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. SharePoint
  4. Dropdown event is not firing when item has been changed.

Dropdown event is not firing when item has been changed.

Scheduled Pinned Locked Moved SharePoint
databasedesign
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Satish Developer
    wrote on last edited by
    #1

    Hi, The dropdown event is not firing when i changed an item in drop down list. Can any one suggest what's going wrong in my code.

    public class FirstWebPart : System.Web.UI.WebControls.WebParts.WebPart
    {
    DataSet _listData;
    string _SelectedValue = string.Empty;
    DropDownList ddlList = new DropDownList();
    DataGrid dgSpListData = new DataGrid();

        public FirstWebPart()
        {
        }
    
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
    
            // TODO: add custom rendering code here.
            
            Label lblAssignedTo = new Label();
            lblAssignedTo.Text = "Assigned To";
    
            string\[\] Members = { "Satish", "Suman", "Saravana" };
            ddlList.DataSource = Members;
            ddlList.DataBind();
    
            this.Controls.Add(lblAssignedTo);
            this.Controls.Add(ddlList);
            
            this.ddlList.SelectedIndexChanged += new EventHandler(\_ddlList\_SelectedIndexChanged);
            this.\_SelectedValue = ddlList.SelectedValue.ToString();
    
            dgSpListData.DataSource = GetListData(\_SelectedValue);
            dgSpListData.DataBind();
            this.Controls.Add(dgSpListData);
            
    
        }
    
        void \_ddlList\_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.\_SelectedValue = ddlList.SelectedValue.ToString();
            //DataGrid dgSpListData = new DataGrid();
            dgSpListData.DataSource = GetListData(\_SelectedValue);
            dgSpListData.DataBind();
            //this.Controls.Add(dgSpListData);
        }
    
        DataSet GetListData(string \_SelectedValue)
        {
            \_listData = new DataSet();
            DataTable \_table = new DataTable();
            DataColumn dc = new DataColumn("Title");
            \_table.Columns.Add(dc);
            dc = new DataColumn("AssignedTo");
            \_table.Columns.Add(dc);
            dc = new DataColumn("Status");
            \_table.Columns.Add(dc);
            using (SPWeb web = SPContext.Current.Site.RootWeb)
            {
                SPList mylist = web.Lists\["MySPList"\];
                SPQuery query = new SPQuery();
                query.Query = "<Where><Eq><FieldRef Name='AssignedTo'/><Value    Type='Text'>" + \_SelectedValue+ "</Value></Eq></Where>";
                SPListItemCollection items = mylist.GetItems(query);
    
    N 1 Reply Last reply
    0
    • S Satish Developer

      Hi, The dropdown event is not firing when i changed an item in drop down list. Can any one suggest what's going wrong in my code.

      public class FirstWebPart : System.Web.UI.WebControls.WebParts.WebPart
      {
      DataSet _listData;
      string _SelectedValue = string.Empty;
      DropDownList ddlList = new DropDownList();
      DataGrid dgSpListData = new DataGrid();

          public FirstWebPart()
          {
          }
      
          protected override void CreateChildControls()
          {
              base.CreateChildControls();
      
              // TODO: add custom rendering code here.
              
              Label lblAssignedTo = new Label();
              lblAssignedTo.Text = "Assigned To";
      
              string\[\] Members = { "Satish", "Suman", "Saravana" };
              ddlList.DataSource = Members;
              ddlList.DataBind();
      
              this.Controls.Add(lblAssignedTo);
              this.Controls.Add(ddlList);
              
              this.ddlList.SelectedIndexChanged += new EventHandler(\_ddlList\_SelectedIndexChanged);
              this.\_SelectedValue = ddlList.SelectedValue.ToString();
      
              dgSpListData.DataSource = GetListData(\_SelectedValue);
              dgSpListData.DataBind();
              this.Controls.Add(dgSpListData);
              
      
          }
      
          void \_ddlList\_SelectedIndexChanged(object sender, EventArgs e)
          {
              this.\_SelectedValue = ddlList.SelectedValue.ToString();
              //DataGrid dgSpListData = new DataGrid();
              dgSpListData.DataSource = GetListData(\_SelectedValue);
              dgSpListData.DataBind();
              //this.Controls.Add(dgSpListData);
          }
      
          DataSet GetListData(string \_SelectedValue)
          {
              \_listData = new DataSet();
              DataTable \_table = new DataTable();
              DataColumn dc = new DataColumn("Title");
              \_table.Columns.Add(dc);
              dc = new DataColumn("AssignedTo");
              \_table.Columns.Add(dc);
              dc = new DataColumn("Status");
              \_table.Columns.Add(dc);
              using (SPWeb web = SPContext.Current.Site.RootWeb)
              {
                  SPList mylist = web.Lists\["MySPList"\];
                  SPQuery query = new SPQuery();
                  query.Query = "<Where><Eq><FieldRef Name='AssignedTo'/><Value    Type='Text'>" + \_SelectedValue+ "</Value></Eq></Where>";
                  SPListItemCollection items = mylist.GetItems(query);
      
      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2
      1. Set AutoPostBack = true on the dropdown 2) using (SPWeb web = SPContext.Current.Site.RootWeb) You don't dispose of objects obtained from the SPContext 3) You don't need to create a DataTable from the SPListItemCollection. Use GetDataTable method.

      I know the language. I've read a book. - _Madmatt

      modified on Monday, October 4, 2010 8:39 AM

      S 1 Reply Last reply
      0
      • N Not Active
        1. Set AutoPostBack = true on the dropdown 2) using (SPWeb web = SPContext.Current.Site.RootWeb) You don't dispose of objects obtained from the SPContext 3) You don't need to create a DataTable from the SPListItemCollection. Use GetDataTable method.

        I know the language. I've read a book. - _Madmatt

        modified on Monday, October 4, 2010 8:39 AM

        S Offline
        S Offline
        Satish Developer
        wrote on last edited by
        #3

        Thanks for your reply. It works for me ;)

        G. Satish

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups