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
Post a Comment