Sunday, 5 July 2015

Event Bubbling



GridOperation.ASPX


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridOperation.aspx.cs" Inherits="UC_to_UC.LucyJobs.GridOperation" %>

<%@ Register src="ShowGrid.ascx" tagname="ShowGrid" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   
    <div>
       
        <uc1:ShowGrid ID="ShowGrid1" runat="server" />
       
    </div>
    </form>
</body>
</html>



Pager.ASCX

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Pager.ascx.cs" Inherits="UC_to_UC.LucyJobs.Pager" %>
<asp:DropDownList ID="ddlPager" runat="server" AutoPostBack="True"
    onselectedindexchanged="ddlPager_SelectedIndexChanged">
    <asp:ListItem>1</asp:ListItem>
    <asp:ListItem>2</asp:ListItem>
    <asp:ListItem>3</asp:ListItem>

</asp:DropDownList>


Pager.ASCX.cs

namespace UC_to_UC.LucyJobs
{
    public partial class Pager : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public delegate void GetPageIndexEventHandler(CustomEventArgs e);
        public event GetPageIndexEventHandler getPageCustomEvent;

        protected void ddlPager_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (getPageCustomEvent != null)
            {
                CustomEventArgs cArgs = new CustomEventArgs();
                cArgs.PageNum = int.Parse(ddlPager.SelectedValue);
                getPageCustomEvent(cArgs);

            }

        }
    }
}


ShowGrid.ASCX


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ShowGrid.ascx.cs" Inherits="UC_to_UC.LucyJobs.ShowGrid" %>
<%@ Register src="Pager.ascx" tagname="Pager" tagprefix="uc1" %>
<asp:GridView ID="gvStudents" runat="server" AllowPaging="true" PageSize="3" PagerSettings-Visible="false">
</asp:GridView>

<uc1:Pager ID="Pager1" runat="server" />


ShowGrid.ASCX.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UC_to_UC.LucyJobs
{
    public partial class ShowGrid : System.Web.UI.UserControl
    {

        
        List<student> oStudList = null;
        protected void Page_Load(object sender, EventArgs e)
        {

            
                oStudList = new List<student>()
            { 
                new student{roll=1,Name="Srikanta",Dept="MCA"},
                new student{roll=2,Name="Sriram", Dept="MBA"},
                new student{roll=3,Name="Susant",Dept="BA"},
                new student{roll=4,Name="Srikanta1",Dept="MCA"},
                new student{roll=5,Name="Sriram1", Dept="MBA"},
                new student{roll=6,Name="Susant1",Dept="BA"},
                new student{roll=7,Name="Srikanta2",Dept="MCA"},
                new student{roll=8,Name="Sriram2", Dept="MBA"},
                new student{roll=9,Name="Susant2",Dept="BA"},
                new student{roll=10,Name="Srikanta3",Dept="MCA"},
                new student{roll=11,Name="Sriram3", Dept="MBA"},
                new student{roll=12,Name="Susant3",Dept="BA"}
             };

                if (!IsPostBack)
                {
                gvStudents.DataSource = oStudList;
                gvStudents.DataBind();
                gvStudents.PageIndex = 0;
            }
            else
            {
                Pager1.getPageCustomEvent += new Pager.GetPageIndexEventHandler(Pager1_getPageCustomEvent);
            }
        }

        void Pager1_getPageCustomEvent(CustomEventArgs e)
        {
            BindStudentData(e.PageNum);
        }

              

        public void BindStudentData(int PageNum)
        {
           // gvStudents.DataSource = null;
            oStudList = new List<student>()
            { 
                new student{roll=1,Name="Srikanta",Dept="MCA"},
                new student{roll=2,Name="Sriram", Dept="MBA"},
                new student{roll=3,Name="Susant",Dept="BA"},
                new student{roll=4,Name="Srikanta1",Dept="MCA"},
                new student{roll=5,Name="Sriram1", Dept="MBA"},
                new student{roll=6,Name="Susant1",Dept="BA"},
                new student{roll=7,Name="Srikanta2",Dept="MCA"},
                new student{roll=8,Name="Sriram2", Dept="MBA"},
                new student{roll=9,Name="Susant2",Dept="BA"},
                new student{roll=10,Name="Srikanta3",Dept="MCA"},
                new student{roll=11,Name="Sriram3", Dept="MBA"},
                new student{roll=12,Name="Susant3",Dept="BA"}
             };
            gvStudents.DataSource = oStudList;
            gvStudents.DataBind();
            gvStudents.PageIndex = PageNum;
            
        }
    }
}

Student.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace UC_to_UC.LucyJobs
{
    public class student
    {
        public int roll { get; set; }
        public string Name { get; set; }
        public string Dept { get; set; }
    }
}

CustomEventArgs.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace UC_to_UC
{
    public class CustomEventArgs:EventArgs
    {
        // Declare a Code property of type string:
        int _iPageNum;
        public int PageNum
        {
            get
            {
                return _iPageNum;
            }
            set
            {
                _iPageNum = value;
            }
        }
    }
}

No comments:

Post a Comment