【发布时间】:2014-04-30 10:22:11
【问题描述】:
我正在尝试在单击按钮时在表格行中添加值。它在数据库上工作,但不在网页上工作。它覆盖页面的最后一行。
如何在每次点击按钮时生成新行。
这是我的按钮点击代码--
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();
}
请帮帮我。
【问题讨论】:
-
Page_Load 中有哪些代码?
-
添加 page_Load 代码。
-
你在哪里填表?当按下按钮时,创建回发并重新加载页面。所以逻辑上你的表应该是空的。我错了吗?
-
如何填表。我知道如何绑定gridview。但是如何绑定表格。
-
请有任何建议!