What i have is
TextBox1
TextBox2
Button
AspTable
I want a row to be added contatining Textbox1.Text each time i click the button, for this i need array of session so that i can store the value of Textbox1.Text in every click
Here is my code but it is resulting an object reference error plz check it out.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Collections;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
string[] a;
public void AddNewRow(int count)
{
TableRow r;
TableCell c1,c2,c3,c4,c5;
for (int i = 0; i <= count; i++)
{
r = new TableRow();
c1 = new TableCell();
c1.Controls.Add(new LiteralControl(Session[a[i]].ToString()));//to take each time the TextBox1.Text value
r.Cells.Add(c1);
Table1.Rows.Add(r);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Session["RowsAdded"] = -1;
a = new string[5];//to store the values of TextBox1.Text by giving it to a session
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
int s=(int)Session["RowsAdded"]+1;
Session["RowsAdded"] = s;
a[s] = DropDownList1.Text;//results object reference is not set to an instance of an object
Session[a[s]] = a[s];
for (int counter = 0; counter <= (int)Session["RowsAdded"]; counter++)
AddNewRow(counter);
}
}
Thank you

New Topic/Question
Reply




MultiQuote



|