Hi...
I am new to ASP.NET. And I am trying to create a dynamic table and delete a particular row.
I am creating buttons and when user click the button the corresponding row will be deleted.
I have done the adding buttons and adding the button's function. but i am confused what to write to delete the row for clicking a particular button...
asptable.aspx
<
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Rows:
<asp:TextBox ID="tbxRows" runat="server" Width="60px"></asp:TextBox>
<br />
Columns:
<asp:TextBox ID="tbxColumns" runat="server" Width="53px"></asp:TextBox>
<br />
<asp:Button ID="btnCreateTable" runat="server" onclick="btnCreateTable_Click"
Text="Create Table" />
<br />
<asp:Table ID="tblDynamicTable" runat="server" Caption="Dynamic Table">
</asp:Table>
</div>
</form>
</body>
</html>
>
asptable.cs
public partial class ASPTable : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCreateTable_Click(object sender, EventArgs e)
{
for (int i = 0; i < Convert.ToInt16(tbxRows.Text); i++)
{
TableRow tr = new TableRow();
for (int j = 0; j < Convert.ToInt16(tbxColumns.Text); j++)
{
TableCell tcID = new TableCell();
TableCell tcValue = new TableCell();
TableCell tcButton = new TableCell();
tcID.Text = (i%7).ToString();
tcValue.Text = Enum.GetNames(typeof( DayOfWeek))[i%7];
Button btnDeleteButton = new Button();
btnDeleteButton.Text = "Delete"+(i%7).ToString()+j.ToString();
btnDeleteButton.ID = "btnDelete" + i.ToString() + j.ToString();
btnDeleteButton.Click += new EventHandler(btnDeleteButton_Click);
tcButton.Controls.Add(btnDeleteButton);
tr.Cells.Add(tcID);
tr.Cells.Add(tcValue);
tr.Cells.Add(tcButton);
}
tblDynamicTable.Rows.Add(tr);
}
}
void btnDeleteButton_Click(object sender, EventArgs e)
{
//throw new NotImplementedException();
}
}