<asp:GridView ID="GridView1" autogenerateselectbutton="True" selectedindex="0"
autogeneratecolumns="True" allowpaging="true" runat="server" CssClass="style39"
datakeynames="Email" RowCommand="GridView1_RowCommand" ShowSelectButton="True">>
我在网格视图中有这个选择按钮。我在页面中有一个删除按钮。我想删除所选行,但是如何将值传递给delete函数,以便我可以编写代码来删除数据库中的选定行。我想知道选择哪一行如何传递值。
我的网格视图有一个名为电子邮件和用户名的列。我想传递选定的行电子邮件。感谢
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 And tbl_usergroups.tbl_group_GroupID =@Email", connectionString);
command.Parameters.Add("@Email", MySqlDbType.VarChar, 25);
command.Parameters["@Email"].Value = Email;
答案 0 :(得分:1)
使用Gridview的RowCommand
事件
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "CommandName")
{
String Email = e.CommandArgument.ToString(); // will Return current Row primary key value
//..Put deletion code here....
//.....
}
}
答案 1 :(得分:0)
如果您需要更多帮助,请与我们联系。