keep adding data in current row unless i press the clear button to change row

i want to keep adding data in current row of grid unless i press clear button to change row but when ever i start adding data in new added row it creates a new row . I want to hold previous rows . any help !!!

   public partial class WebForm5 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!(IsPostBack))
        {
            Session["List"] = null;
            ViewState["i"] = ViewState["j"] = 1;
            ViewState["state"] = "";


        }
    }
    public static DataTable dt;
    public static int i = 1;
    protected void txtName_Click(object sender, EventArgs e)
    {

        Session["List"] = dt;
        dt = new DataTable();
        DataRow dr = null;

        dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
        dt.Columns.Add(new DataColumn("Column1", typeof(string)));
        if (Convert.ToInt16 (ViewState ["i"]) ==Convert.ToInt16( ViewState["j"]))
        {

          // here i have to add something
                dr = dt.NewRow();
                ViewState["state"] = txtName.Text;
                dr["RowNumber"] = i;
                dr["Column1"] = Convert.ToString(ViewState["state"]) + txtName.Text;
                dt.Rows.Add(dr);


        }
        else if  ( Convert .ToInt16 ( ViewState["i"] )!=  Convert .ToInt16 ( ViewState["j"]))
        {

             if (Session["List"] != null)
            {
                dt = (DataTable)Session["List"];
                dr = dt.NewRow();
                dr["Column1"] =  txtName.Text;
                dr["RowNumber"] = i;
                ViewState["state"] = txtName.Text;
                dt.Rows.Add(dr);
                //lst = (List<string>)Session["List"];
                //lst.Insert(i,txtAdd.Text);
                //i++;

            }

            ViewState["i"] = ViewState["j"];
        }
        grdData.DataSource = dt;
        grdData.DataBind();
    }

    protected void btnClr_Click(object sender, EventArgs e)
    {
        ViewState["j"] = i++;
    }
}

Answers


public partial class WebForm5 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!(IsPostBack)) { Session["List"] = null; ViewState["i"] = ViewState["j"] = 1; ViewState["state"] = "";

        }
    }
    public static DataTable dt;
    public static int i = 1;
    protected void txtName_Click(object sender, EventArgs e)
    {

        Session["List"] = dt;
        dt = new DataTable();
        DataRow dr = null;

        dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
        dt.Columns.Add(new DataColumn("Column1", typeof(string)));
        if (Session["List"] == null)
        {
            if (Convert.ToInt16(ViewState["i"]) == Convert.ToInt16(ViewState["j"]))
            {
                dr = dt.NewRow();
                dr["RowNumber"] = i;
                dr["Column1"] = Convert.ToString(ViewState["state"]) + txtName.Text;
                ViewState["state"] = Convert.ToString(ViewState["state"]) + txtName.Text;
                dt.Rows.Add(dr);



            }
            grdData.DataSource = dt;
            grdData.DataBind();
        }

              if (Session["List"] != null)
            {
      if  ( Convert .ToInt16 ( ViewState["i"] )!=  Convert .ToInt16 ( ViewState["j"]))
        {


                dt = (DataTable)Session["List"];
                dr = dt.NewRow();
                dr["Column1"] =  txtName.Text;
                dr["RowNumber"] = i;

                dt.Rows.Add(dr);
                //lst = (List<string>)Session["List"];
                //lst.Insert(i,txtAdd.Text);
                //i++;
                grdData.DataSource = dt;
                grdData.DataBind();
            }
      else if (Convert.ToInt16(ViewState["i"]) == Convert.ToInt16(ViewState["j"]))
      {
          dt = (DataTable)Session["List"];
         ViewState["state"] = grdData.Rows[((grdData.Rows.Count) - 1)].Cells[1].Text;
         string i =Convert.ToString( ViewState["state"]);
         int j = dt.Rows.Count;
          dt.Rows[(dt.Rows.Count)-1]["Column1"] =Convert.ToString(ViewState["state"])+ txtName.Text;
          grdData.DataSource = dt;
          grdData.DataBind();
      }

            ViewState["i"] = ViewState["j"];
        }
       txtName.Text = "";


    }

    protected void btnClr_Click(object sender, EventArgs e)
    {
        ViewState["j"] = i++;
        ViewState["state"] = "";
       // txtName.Text = grdData.Rows[(grdData.Rows.Count - 1)].Cells[1].Text;

    }

    protected void btnnew_Click(object sender, EventArgs e)
    {

        dt.Rows[(grdData.Rows.Count - 1)]["Column1"] = txtName.Text;
        grdData.DataSource = dt;
        grdData.DataBind();
    }
}

Need Your Help

Downloading multiple files from remote location with progress bar

php jquery ajax download

I need to implement a feature where a user can paste one or more YouTube links, a PHP script then downloads all of them to the server, displays progress bar for each download and then inserts relev...

div with curved border, no corners

html css border css-shapes margins

I have to make a container with very strange margins. I tried to make it with :after and :before, but had problems with borders style.Image of a div I have to create