我可以使用LinkButton
來知道如何從GridView
中刪除行嗎?我在谷歌找到的代碼使用數據綁定GridView
。我根據使用DropDownList
選擇的信息來綁定信息。由於從數據庫C中刪除選定的數據#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string username;
username = HttpContext.Current.User.Identity.Name;
if (DropDownList1.SelectedValue.Equals("Expired"))
{
SqlConnection conn4 = new SqlConnection(My connection);
SqlDataAdapter adapter;
string mySQL2;
mySQL2 =
"SELECT Title,MessageStatus From Table_Message WHERE Username ='"
+ username
+ "' AND MessageStatus = 'Expired' AND Method = 'Email'";
adapter = new SqlDataAdapter(mySQL2, conn4);
conn4.Open();
DataSet ds3 = new DataSet();
adapter.Fill(ds3);
//Execute the sql command
GridView1.DataSource = ds3;
GridView1.DataBind();
conn4.Close();
}
else if (DropDownList1.SelectedValue.Equals("Pending"))
{
SqlConnection conn3 = new SqlConnection(My connection);
SqlDataAdapter adapter1;
string mySQL;
mySQL =
"SELECT Title,MessageStatus From Table_Message WHERE Username ='"
+ username
+ "' AND MessageStatus = 'Pending' AND Method = 'Email'";
adapter1 = new SqlDataAdapter(mySQL, conn3);
conn3.Open();
DataSet ds2 = new DataSet();
adapter1.Fill(ds2);
//Execute the sql command
GridView1.DataSource = ds2;
GridView1.DataBind();
conn3.Close();
}