0
<asp:GridView ID="GridView1" autogenerateselectbutton="True" selectedindex="0"
autogeneratecolumns="True" allowpaging="true" runat="server" CssClass="style39"
datakeynames="Email" RowCommand="GridView1_RowCommand" ShowSelectButton="True">>
在我的網格視圖中有這個選擇按鈕。我在頁面中有一個刪除按鈕。我想刪除選中的行,但是如何將值傳遞給刪除函數,以便我可以編寫代碼來刪除數據庫中選定的行。我想知道哪一行被選中如何傳遞值。在網格視圖中選擇按鈕
我的網格視圖有一個名爲電子郵件和用戶名的列。我想傳遞選定的行電子郵件。由於
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "CommandName")
{
String Email = e.CommandArgument.ToString(); // will Return current Row primary key value
MySqlConnection connectionString = new MySqlConnection("Server=127.0.0.1;Database=surelyknown;Uid=root");
connectionString.Open();
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlCommand command = new MySqlCommand();
command = new MySqlCommand("DELETE from tbl_group, tbl_usergroups using tbl_group inner join tbl_usergroups where tbl_group.GroupID [email protected] And tbl_usergroups.tbl_group_GroupID [email protected]", connectionString);
command.Parameters.Add("@Email", MySqlDbType.VarChar, 25);
command.Parameters["@Email"].Value = Email;
執行沒有調用GridView1_RowCommand – rookie
在頁面加載中,您再次綁定數據,它應該像...... if(!IspostBack){綁定數據gridview在這裏..} –