Skip to main content

Binding Linked List to GridView




PreRequirements :   You need to know how to create a Linked list and basic of GridView component. If you don't know how to create a simple Linked List you may fallow my previous post regarding Linked List in ASP.Net. 

To Bind the Linked List to GridView first you need to place GridView component on you 
Web Page. Then on .aspx page  .. you need to add following code .. you may extend it as per your requirements.

<asp:GridView ID="GridView1" runat="server" Width="16px"
            Height="50px" ToolTip="Unique Words and Freq"
                  onselectedindexchanged="GridView1_SelectedIndexChanged1">
                <columns>
                <asp:TemplateField HeaderText="Words">
                  <itemtemplate>
                    <asp:Label ID="w" runat="server" Text='<%#Eval("Words") %>'> </asp:Label>
                  </itemtemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Freq">
                  <itemtemplate>
                    <asp:Label ID="w" runat="server" Text='<%#Eval("Frequency") %>'> </asp:Label>
                  </itemtemplate>
                </asp:TemplateField>
                </columns>
              </asp:GridView>


Here i tried to bind a List having two Properties Word and Frequency. You have to use Eval Function with label component. This will show your List's Data in GridView. TampleField is used to show your column  Heading. You may extend it further for different fields for you List.


In code session (aspx.cs) file ..

You need to set GridView property AutoGenerateColomns = false. So, that it will generate columns according to your requirement.  

            GridView1.AutoGenerateColumns = false;

Then you may define DataSource to your custom List. Here I have object of my List class is List1.

            GridView1.DataSource = List1;

At end Bind the GridView using DataBind() Function.
            GridView1.DataBind();



Tested and working.
Hope it will helpful to you.

Comments

Popular posts from this blog

Font identifier and Unicode converter for Hindi

Font identifier and Unicode converter for Hindi Fonts are used to represent text in document. Fonts are mainly two kind non-Unicode and Unicode fonts. Complex scripts like Hindi and other Asian languages well represented in Unicode fonts. There are some other ways to write these languages for e.g we can use ASCII/ISCII codes to represent different characters of Hindi, but there are large numbers of characters in Hindi script as compared to English. Therefore, we always need multiple ASCII/ISCII encoded characters combination to represent a single character of Hindi Script. One major problem in these ASCII encoding based fonts is that we cannot easily transfer text from one system to another. The system must have these text fonts. There is hundreds of ASCII/ISCII encoding based fonts which are used to write Hindi text. New software systems are based on Unicode fonts.                   ...

Hindi to Punjabi Machine Translation System

The Hindi To Punjabi Machine Translation System has been developed using Direct/Rule based Approach by Dr.Vishal Goyal and Dr. G.S Lehal. Various large size Lexicon resources  have been used to map Source and Target language words.  In general, if the two languages are structurally similar, in particular as regards lexical correspondences, morphology and word order, the case for abstract syntactic analysis seems less convincing. Since the present research work deals with a pair of closely related language, so the direct translation system is the obvious choice. The overall system architecture shown below, is adopted for Hindi to Punjabi Machine Translation System. The system is divided into three stages: Preprocessing, Translation Engine, and Post Processing stage. Following is the description of various steps of this architecture.  PreProcessing   The pre-processing stage is a collection of operations that are applied on input  data to make it pr...

Sort Numbers using Three Stacks

The Program was developed to Sort Numbers using Three Stacks. Initially, all the Numbers are in Stack One, then other Two Stacks used to Sort the Number. Max Limit of Number in the array is 100, You may increase it.  The program read all input numbers from Text File present in C:\ drive The Program was developed using VC++.net Code is Very simple and understandable, you may optimize it. #include&ltfstream&gt #include&ltiostream&gt #include&ltstdio.h&gt #include&ltstring&gt using namespace std; typedef struct { int top; float arr[ 100 ]; }Stack; void createStack (Stack *stack) { stack->top=- 1 ; } void push (Stack *stack, float ele) { if (stack->top==- 1 ) { stack->arr[ 0 ]=ele; stack->top= 0 ; } else stack->arr[++(stack->top)]=ele; } float pop (Stack *stack) { if (stack->top==- 1 ) return - 1 ; return stack->arr[(stack->top)--]; } float peek (Stack *stack) { if (stack->top==-...