触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > LinkButton获取GridView的数据库ID

前台:
<asp:LinkButton  ID="LinkButton1" runat="server" onclick="LinkButton1_Click">删除</asp:LinkButton>

后台: 
   protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton myB = (LinkButton)sender;
        int myIndex = ((GridViewRow)myB.NamingContainer).RowIndex;//获得行号 
        int myId = Convert.ToInt16(GridView1.DataKeys[myIndex].Value);//获得id

        Conn conn = new Conn();
        SqlConnection con = conn.getConn();
        SqlCommand sqlcom;
        string sqlstr = "delete from news where id='" + myId + "'";
                sqlcom = new SqlCommand(sqlstr, con);
                sqlcom.ExecuteNonQuery();
        con.Close();
        bind();
    }


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com