這是刪除一行代碼:刪除的GridView從GridView中刪除的行數據直接
else if (e.CommandName == "Deleterow")
{
GridViewRow gr = (GridViewRow)
((Button)e.CommandSource).NamingContainer;
SqlCommand com = new SqlCommand("StoredProcedure4", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@ID", gr.Cells[0].Text);
com.ExecuteNonQuery();
}
ASPX:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
SqlConnection con = Connection.DBconnection();
if (e.CommandName == "EditRow")
{
GridViewRow gr = (GridViewRow)((Button)e.CommandSource).NamingContainer;
Textid.Text = gr.Cells[0].Text;
Textusername.Text = gr.Cells[1].Text;
Textclass.Text = gr.Cells[2].Text;
Textsection.Text = gr.Cells[3].Text;
Textaddress.Text = gr.Cells[4].Text;
}
else if (e.CommandName == "Deleterow")
{
GridViewRow gr = (GridViewRow)((Button)e.CommandSource).NamingContainer;
SqlCommand com = new SqlCommand("StoredProcedure4", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@ID", gr.Cells[0].Text);
com.ExecuteNonQuery();
}
}
當我刪除按鈕,它刪除數據行重新加載頁面後。
所以我需要直接從gridview刪除行。
對於該做什麼,任何人都可以幫忙嗎?
感謝,
無需重新加載頁面只是重新綁定網格com.ExecuteNonQuery後(); –
而不是使用'Response.Redirect()'重新綁定你的gridview – Prabhat
@Rani:你的** Page_Load **內容。這對我們來說更容易給你適當的解決方案。 – Prabhat