How Can bind Telerik RadGrid With Data

How Can bind Telerik RadGrid  With Data

For doing this you have download Telerik toolkit first from Telerik Website.
So Here we are binding Telerik Radgrid   by using two methods…
1)      By Simple DataSourse  and DataBind Property.
2)      By NeedDataSourse Event.  

Step 1: Design Web Form .aspx page

<div>
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <telerik:RadGrid ID="rad_grd" runat="server"
                CellSpacing="0" GridLines="None" AutoGenerateColumns="true">
                <HeaderStyle HorizontalAlign="Left" />
                <MasterTableView>
                </MasterTableView>
            </telerik:RadGrid>

            <br />
            <br />
            By Need Datasorce
        <br />
            <br />
            <telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0"
                GridLines="None" AutoGenerateColumns="false"
                OnNeedDataSource="RadGrid1_NeedDataSource">
                <HeaderStyle HorizontalAlign="Left" />
                <MasterTableView DataKeyNames="name" AutoGenerateColumns="false">
                    <NoRecordsTemplate>No records found.</NoRecordsTemplate>

                    <Columns>
                        <telerik:GridBoundColumn HeaderText="Name" DataField="Name" />
                        <telerik:GridBoundColumn HeaderText="Amount" DataField="Amount" />
                        <telerik:GridBoundColumn HeaderText="Phone" DataField="Phone" />
                    </Columns>


                </MasterTableView>
            </telerik:RadGrid>
        </div>

Step 2: Logic on .CS page


  protected void Page_Load(object sender, EventArgs e)
    {

        bind_gr();
    }

    //For rad_grd

    public void bind_gr()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Name");
        dt.Columns.Add("Amount");
        dt.Columns.Add("Phone");


        dt.Rows.Add("Kandy", "12", "8802***2564");
        dt.Rows.Add("Sam", "25", "545502*2544");
        dt.Rows.Add("Izhar", "32", "95802*2452");
        dt.Rows.Add("Vineet", "10.2", "88022564***");


        dt.Rows.Add("Kandy", "0.12", "8802***2564");
        dt.Rows.Add("Sam", "12", "545502*2544");
        dt.Rows.Add("Izhar", "215", "95802*2452");
        dt.Rows.Add("Vineet", "11.00", "88022564***");
        dt.Rows.Add("Kandy", "0.12", "8802***2564");
        dt.Rows.Add("Sam", "12", "545502*2544");
        dt.Rows.Add("Izhar", "215", "95802*2452");
        dt.Rows.Add("Vineet", "11.00", "88022564***");
        dt.Rows.Add("Kandy", "0.12", "8802***2564");
        dt.Rows.Add("Sam", "12", "545502*2544");
        dt.Rows.Add("Izhar", "215", "95802*2452");
        dt.Rows.Add("Vineet", "11.00", "88022564***");

        rad_grd.DataSource = dt;
        rad_grd.DataBind();

    }
   
   
    //For RadGrid1

    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Name");
        dt.Columns.Add("Amount");
        dt.Columns.Add("Phone");


        dt.Rows.Add("Kandy", "12", "8802***2564");
        dt.Rows.Add("Sam", "25", "545502*2544");
        dt.Rows.Add("Izhar", "32", "95802*2452");
        dt.Rows.Add("Vineet", "10.2", "88022564***");


        dt.Rows.Add("Kandy", "0.12", "8802***2564");
        dt.Rows.Add("Sam", "12", "545502*2544");
        dt.Rows.Add("Izhar", "215", "95802*2452");
        dt.Rows.Add("Vineet", "11.00", "88022564***");
        dt.Rows.Add("Kandy", "0.12", "8802***2564");
        dt.Rows.Add("Sam", "12", "545502*2544");
        dt.Rows.Add("Izhar", "215", "95802*2452");
        dt.Rows.Add("Vineet", "11.00", "88022564***");
        dt.Rows.Add("Kandy", "0.12", "8802***2564");
        dt.Rows.Add("Sam", "12", "545502*2544");
        dt.Rows.Add("Izhar", "215", "95802*2452");
        dt.Rows.Add("Vineet", "11.00", "88022564***");

        RadGrid1.DataSource = dt;
        // rad_grd_ComponentDrillThorugh.DataBind();



    }


It Will Look like :-




Comments

Popular posts from this blog

Create and save QR code in asp.net with C#

Change text of RadGrid Header Dynamically

Telerik Radwindow Open on Button Click