suri_vinod:But my problem is i dont want to ask user about number of rows or columns.
User should be able to click some link, say more, and add as many textboxes they want.
which should be very simple too. use a LinkButton with Text, say, "More" or "AddRows", something like:
<asp:LinkButton ID="LinkButton1" runat="server" Text="AddRows" OnClick="LinkButton1_OnClick"/>
and in the OnClick event handler, write code similar to what's in the Button1_Click, the example Vinz has given you.
except that you won't be parsing the values of the number of rows and column from the textboxes but will use some predefined or hard-coded values.
you can use the same variables, numOfColumns and numOfRows and set up their values in the page load event...so you won't need these lines that I've crossed out:
protected void LinkButton1_OnClick(object sender, EventArgs e)
{
//Check if the inputs are numbers
if (int.TryParse(TextBox1.Text.Trim(), out numOfColumns) && int.TryParse(TextBox2.Text.Trim(), out numOfRows))
{
//Generate the Table based from the inputs
GenerateTable(numOfColumns, numOfRows);
//Store the current Rows and Columns In ViewState as a reference value when it post backs
ViewState["cols"] = numOfColumns;
ViewState["rows"] = numOfRows;
}
else
{
Response.Write("Values are not numeric!");
}
}
also, it would depend on you to set up the numOfRows value...maybe = 1 as you want the users to add rows every time they click.....that is up to you.