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”));
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();
Gridview1.DataBind();
//Code for .aspx Page
<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”false”>
<Columns>
<asp:TemplateField>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID=”Textbox1″ Text = ‘<%# Container.DataItem %>’ runat=”server”>
<asp:TextBox ID=”Textbox1″ Text = ‘<%# Container.DataItem %>’ runat=”server”>
</asp:TextBox>
</ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</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