0

I am trying to add values in table rows on button click. It's working on database but not working on web page. It override on last row on page.

How can I generate new row on every button click.

here is my button click code--

protected void Page_Load(object sender, EventArgs e)
{
 tblAdd.Visible = false;
 Label1.Visible = false;
 //Label2.Visible = false;
}
protected void btnSave_Click(object sender, EventArgs e)
{
 if (Page.IsValid)
 {
 CheckBox cb1 = new CheckBox();
 I = Hidden1.Value;
 I += 1;
 cb1.ID = "cb1" + I;
 TableRow Table1Row = new TableRow();
 Table1Row.ID = "Table1Row" + I;
 TableCell RCell1 = new TableCell();
 RCell1.Controls.Add(cb1);
 TableCell RCell2 = new TableCell();
 RCell2.Text = txtName.Text;
 tblLanguagesRow.Cells.Add(RCell1);
 tblLanguagesRow.Cells.Add(RCell2);
 tblLanguages.Rows.Add(tblLanguagesRow);
 Hidden1.Value = I;
 btnAdd.Visible = true;
 btnDelete.Visible = true;
 Label2.Visible = true;
 Label2.Text = "Successfully Added";
 add();
 }
 txtName.Text = "";
}
public int add()
{
 string strcon = ConfigurationManager.ConnectionStrings["Dbconnection"].ConnectionString;
 SqlConnection sqlConnection = new SqlConnection(strcon);
 SqlCommand command = new SqlCommand("hrm_AddLanguages", sqlConnection);
 command.CommandType = CommandType.StoredProcedure;
 command.Parameters.Add("@Name", SqlDbType.VarChar).Value = txtName.Text;
 command.Parameters.Add("@CreatedOn", SqlDbType.DateTime).Value = DateTime.Now;
 command.Parameters.Add("@UpdatedOn", SqlDbType.DateTime).Value = DateTime.Now;
 command.Parameters.Add("@CreatedBy", SqlDbType.BigInt).Value = 1;
 command.Parameters.Add("@UpdatedBy", SqlDbType.BigInt).Value = 1;
 command.Parameters.Add("@IsDeleted", SqlDbType.Bit).Value = 0;
 sqlConnection.Open();
 return command.ExecuteNonQuery();
}

Please Help me.

Brian Tompsett - 汤莱恩
5,92772 gold badges63 silver badges135 bronze badges
asked Apr 30, 2014 at 10:22
8
  • What code have in Page_Load ? Commented Apr 30, 2014 at 10:27
  • Added page_Load code. Commented Apr 30, 2014 at 10:33
  • Where do you fill the table? When the button is pressed create post-back and the page reloads. So logically your table should be empty. Am i wrong? Commented Apr 30, 2014 at 10:35
  • How to fill table. I know how to bind gridview. But how can I bind table. Commented Apr 30, 2014 at 10:45
  • any suggestion please ! Commented Apr 30, 2014 at 11:04

1 Answer 1

1

If possible try to do this using Grid view. It is better to use grid view instead of table.

Check out below link. It will help you to find your solution.

DataTable in ASP.Net Session

answered May 12, 2014 at 6:28
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.