Pages

Thursday, July 21, 2011

Bind gridview with array data source

Views

This tip demonstrates how you can bind GridView with an array Datasource.
//Binding gridview with array data source
ArrayList arrayDataSource= new ArrayList();
arrayDataSource.Add(new ListItem(“http://www.asp.net”));
arrayDataSource.Add(new ListItem(“http://www.microsoft.com”));
arrayDataSource.Add(new ListItem(“http://www.dotnetcurry.com”));
arrayDataSource.Add(new ListItem(“http://www.devcurry.com”));
 Gridview1.DataSource = arrayDataSource;
Gridview1.DataBind();
//Code for .aspx Page
<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”false”>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID=”Textbox1″ Text = ‘<%# Container.DataItem %>’ runat=”server”>
          </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Note: Please remember to include ‘<%# Container.DataItem %>’ in the Text property of the textbox in the gridview.

0 comments:

Post a Comment

 

Web Design Company karimnagar, Web Designing warangal, Logo Design Company nizamabad, Indian Website Design Company, maddysoft.co.in