I am creating a DataTable and populating the rows/columns in it.
However when I bind it to a GridView, I cannot see the text I assign to one column.
Code:
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
DataRow dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["Column1"] = "some text";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["RowNumber"] = 2;
dr["Column1"] = "more text";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["RowNumber"] = 3;
dr["Column1"] = "and more text";
dt.Rows.Add(dr);
Gridview2.DataSource = dt;
Gridview2.DataBind();
The gridview only displays the first Column (with the numbers 1-3) but the 2nd column with the text does not display on the gridview.
Any ideas?
Thanks!
EDIT: The 1st column gridview is in BoundField whereas the 2nd column is within TemplateFied...ItemTemplate.
<asp:gridview ID="Gridview2" runat="server" ShowFooter="true" GridLines="None"
AutoGenerateColumns="false" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="#" ItemStyle-Width="30px" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="300"></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="ButtonAdd1" runat="server" Text="Add Statement" onclick="ButtonAdd1_Click" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>