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. ASP.NET
  4. Return List<> from user control & bind to parent page grid.

Return List<> from user control & bind to parent page grid.

Scheduled Pinned Locked Moved ASP.NET
questioncsstutorial
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.
  • Z Offline
    Z Offline
    zeego
    wrote on last edited by
    #1

    Hi, I want to return selected items (check box list) on button click of a user control to the parent page. How do I do this ? The checked items would be in form of List<>. I have made the user control but don't know how to pass an input id to it to fetch the records and on button click, return them.

    L 1 Reply Last reply
    0
    • Z zeego

      Hi, I want to return selected items (check box list) on button click of a user control to the parent page. How do I do this ? The checked items would be in form of List<>. I have made the user control but don't know how to pass an input id to it to fetch the records and on button click, return them.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Just make one public method of your user control which returns List<> items [Contains selected items]. That's it. You need to access that particular method once button click is over. HTH

      Jinal Desai - LIVE Experience is mother of sage....

      Z 1 Reply Last reply
      0
      • L Lost User

        Just make one public method of your user control which returns List<> items [Contains selected items]. That's it. You need to access that particular method once button click is over. HTH

        Jinal Desai - LIVE Experience is mother of sage....

        Z Offline
        Z Offline
        zeego
        wrote on last edited by
        #3

        Update: Ok, I created two public properties, now I want to return the selected checkbox items in the checkbox list and return them on button click so I used a foreach, not much sure about my approach.Here is how its looking now. How to bind the results with parent page gridview on user control button click ?

        public partial class assets_WebControls_ftExclusions : System.Web.UI.UserControl
        {
        private int id; // the id passed from parent page
        private ftExclusionsList myftExclusions; // the list to return to master page

        public  int ID
        {
            get{return ID;}
            set{ID=value;}
        }
        
        public ftExclusionsList selectedExclusions
        {
            get { return myftExclusions; }
            set { myftExclusions = value; }
        }
        
        protected void Page\_Load(object sender, EventArgs e)
        {
        

        // Just binding the checkbox list with selected items/total items
        if (!Page.IsPostBack)
        {
        cblExclusions.DataBind();
        ftExclusionsList myExcluList = ftExclusionsManager.ftExclusionsById(ID);
        if (myExcluList != null)
        {
        if (myExcluList.Count > 0 && myExcluList != null)
        {
        foreach (ftExclusions ex in myExcluList)
        {
        cblExclusions.Items.FindByValue(ex.excluId.ToString()).Selected = true;
        }
        }
        }
        }

        }
        protected void btnUpdate\_Click(object sender, EventArgs e)
        {// returning result set here how to bind it with gridview on parent page ? :( 
            ftExclusionsList myFTExclusionList = new ftExclusionsList();
            foreach (ListItem li in cblExclusions.Items)
            {
                if (li.Selected == true)
                {
                    ftExclusions myftExclusion = new ftExclusions();
                    myftExclusion.ftExcluId = Convert.ToInt32(li.Value);
                    myftExclusion.excludesc = li.Text.ToString();
                    myFTExclusionList.Add(myftExclusion);
                }
                
            }
            selectedExclusions = myFTExclusionList;
        }
        

        }

        modified on Friday, May 28, 2010 7:53 AM

        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