[英]I have gridview which fetches data from sql server, i have action buttons edit delete update and cancel
I have a gridview which fetches data from SQL server, I have action buttons edit delete update and cancel.我有一个 gridview 从 SQL 服务器获取数据,我有操作按钮编辑删除更新和取消。
I have a code but I don't know how to implement iti.e click events for the edit delete cancel update operations.我有一个代码,但我不知道如何为编辑删除取消更新操作实现 iti.e 点击事件。
asp code
<Columns>
<asp:BoundField DataField="group" HeaderText="group" SortExpression="group" />
<asp:BoundField DataField="key" HeaderText="key" SortExpression="key" />
<asp:BoundField DataField="label" HeaderText="label" SortExpression="label" />
<asp:CommandField ButtonType="Button" CancelText="" HeaderText="Action" ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
code behind C# C# 后面的代码
protected void GridView_RowEditing1(object sender, GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
BindGrid();
}
protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);
GridViewRow row = (GridViewRow)GridView.Rows[e.RowIndex];
Label lbldeleteid = (Label)row.FindControl("lblID");
con.Open();
SqlCommand cmd = new SqlCommand("delete FROM detail where id='" + Convert.ToInt32(GridView.DataKeys[e.RowIndex].Value.ToString()) + "'", con);
cmd.ExecuteNonQuery();
con.Close();
BindGrid();
}
protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);
int Config_id = Convert.ToInt32(GridView.DataKeys[e.RowIndex].Value.ToString());
GridViewRow row = (GridViewRow)GridView.Rows[e.RowIndex];
Label lblID = (Label)row.FindControl("lblID");
//TextBox txtname=(TextBox)gr.cell[].control[];
TextBox group = (TextBox)row.Cells[0].Controls[0];
TextBox key = (TextBox)row.Cells[1].Controls[0];
TextBox label = (TextBox)row.Cells[2].Controls[0];
//TextBox textadd = (TextBox)row.FindControl("txtadd");
//TextBox textc = (TextBox)row.FindControl("txtc");
GridView.EditIndex = -1;
con.Open();
//SqlCommand cmd = new SqlCommand("SELECT * FROM detail", conn);
SqlCommand cmd = new SqlCommand("update detail set group='" + group.Text + "',key='" + key.Text + "',label ='" + label.Text + "'where id='" + Config_id + "'", con);
cmd.ExecuteNonQuery();
con.Close();
BindGrid();
//GridView1.DataBind();
}
protected void GridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView.EditIndex = -1;
BindGrid();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.