I want to make a GridView such that it's first column is sourced from a C# collection and it's second column is a TextField. I followed this link: https://stackoverflow.com/questions/28828150/add-textbox-in-datatable-aspx-net#:~:text=Textbox%20is%20a%20control%20and,will%20have%20the%20relevant%20textbox.
The answer provided me with:My1stOutput Is there a way to interchange the columns?
protected DataTable rGrdV(List<string> slist) {
DataTable dt = new DataTable();
dt.Columns.Add("col1",typeof(String));
foreach (string s in slist)
{
dt.Rows.Add(s);
}
return dt;
}
Desginer:
<asp:GridView ID="GridView1" runat="server" >
<asp:TemplateField>
<ItemTemplate >
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView
Edit___________________________________
I tried changing designer to
<asp:GridView ID="GridView1" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
<Columns>
<asp:BoundField DataField="Col1" HeaderText="MyColumn" />
<asp:TemplateField> <%-- you have not opened it in your markup --%>
<ItemTemplate >
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Now I'm getting My2ndOutput
