Guest User

Guest User

  • Tech Writer
  • 26
  • 3.9k

Add row from textbox to listview

Sep 11 2018 9:34 PM
What should i do? It doesnt add a row even if i already declare a new row.
 
 //This is my behind codes in add button
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dr = dt.NewRow();
dr["Column1"] = "";
dr["Column2"] = TextBox1.Text;
dt.Rows.Add(dr);
ViewState["CurrentTable"] = dt;
ListView1.DataSource = dt;
ListView1.DataBind();
 
 //This is my layout code
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<div >
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td2" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0">
<tr id="Tr2" runat="server">
<th id="Th1" runat="server">ID</th>
<th id="Th2" runat="server">AppName</th>
</tr>
<tr runat="server" id="itemPlaceholder">
</tr>
</table>
</td>
</tr>
</table>
</div>
</LayoutTemplate>
<ItemTemplate>
<div>
<td id="Td1" runat="server"> <%#Eval("Column1") %>
</td>
<td id="Td2" runat="server"> <%#Eval("Column2") %>
</td>
</div>
</ItemTemplate>
</asp:ListView>
 
 
 

Answers (2)