Note that there are some explanatory texts on larger screens.

plurals
  1. POText in DataTable not displayed in GridView
    primarykey
    data
    text
    <p>I am creating a DataTable and populating the rows/columns in it.</p> <p>However when I bind it to a GridView, I cannot see the text I assign to one column.</p> <p>Code:</p> <pre><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(); </code></pre> <p>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.</p> <p>Any ideas?</p> <p>Thanks!</p> <p>EDIT: The 1st column gridview is in BoundField whereas the 2nd column is within TemplateFied...ItemTemplate.</p> <pre><code> &lt;asp:gridview ID="Gridview2" runat="server" ShowFooter="true" GridLines="None" AutoGenerateColumns="false" &gt; &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt; &lt;EditRowStyle BackColor="#999999" /&gt; &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt; &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt; &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt; &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt; &lt;SortedAscendingCellStyle BackColor="#E9E7E2" /&gt; &lt;SortedAscendingHeaderStyle BackColor="#506C8C" /&gt; &lt;SortedDescendingCellStyle BackColor="#FFFDF8" /&gt; &lt;SortedDescendingHeaderStyle BackColor="#6F8DAE" /&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="RowNumber" HeaderText="#" ItemStyle-Width="30px" ItemStyle-HorizontalAlign="Center" /&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox ID="TextBox1" runat="server" Width="300"&gt;&lt;/asp:TextBox&gt; &lt;/ItemTemplate&gt; &lt;FooterStyle HorizontalAlign="Right" /&gt; &lt;FooterTemplate&gt; &lt;asp:Button ID="ButtonAdd1" runat="server" Text="Add Statement" onclick="ButtonAdd1_Click" /&gt; &lt;/FooterTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:gridview&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload