Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Saturday, 30 April 2016

Bind GridView Using Array,List and ArrayList In Asp.Net

 No comments   


Introduction

In this article I will explain how to bind GridView using Array, List and ArrayList .If you are familiar with Arrays, List, Collections in asp.net then this article will be better understable for you.

Description

We don't need to any database ,all the data inserted from backend(.Cs) Page. 

Aspx Page -- -- -- -- -- -- -- --

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField HeaderText="Customer Names">
            <ItemTemplate>
                <%# Container.DataItem %>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Using Array -- -- -- -- -- -- -- --

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        //Populate GridView using Array of string.
        string[] objNames = new string[4];
       objNames [0] = "Jatin Phulera";
       objNames [1] = "Gaurav Pandey";
       objNames [2] = "Nicks Joshi";
       objNames [3] = "King Sam";
       objNames [4] = "Shiv Deopa";

        GridView1.DataSource = objNames;
        GridView1.DataBind();
    }
}

Using ArrayList -- -- -- -- -- -- -- --

Firstly add a namespace on top for using ArrayList 

using System.Collections;

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        //Populate GridView using ArrayList.
        ArrayList objArrayListNames = new ArrayList();
       objArrayListNames.Add("Jatin Phulera");
       objArrayListNames.Add("Gaurav Pandey");
       objArrayListNames.Add("Nicks Joshi");
       objArrayListNames.Add("King Sam");
       objArrayListNames.Add("Shiv Deopa”);

        GridView1.DataSource = objArrayListNames;
        GridView1.DataBind();
    }
}

Using List-- -- -- -- -- -- -- --

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        //Populate GridView using List of string.
        List<string> objListNames = new List<string>();
       objListNames.Add("Jatin Phulera");
       objListNames.Add("Gaurav Pandey");
       objListNames.Add("Nicks Joshi");
       objListNames.Add("King Sam");
       objListNames.Add("Shiv Deopa");
        GridView1.DataSource = objListNames;
        GridView1.DataBind();
    }
}
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write