如何在asp.net中删除Gridview Row [英] how to delete Gridview Row in asp.net

查看:149
本文介绍了如何在asp.net中删除Gridview Row的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网页中,我有Gridview。我在运行时使用databind()方法绑定数据。

然后我删除并编辑网格上的按钮。当我单击按钮时,行被删除或编辑。怎么做



我正在使用以下编码加载数据

In my web page I had Gridview. I am bind datas at runtime using databind() method.
Then I have delete and edit buttons on the grid. When i click the buttons the row is deleted or edited. how to do it

I am using following coding for load datas

Bindgrid()
 connect.cnopen();
        SqlDataAdapter da = new SqlDataAdapter("select ITEM,QTY,RATE,Amount FROM TempSales where Billno='" + TXTBILLNO.Text + "'", connect.cn());
        DataSet ds=new DataSet();
        da.Fill(ds);
        GridView1.DataSource=ds;
        GridView1.DataBind();



我为删除行提供以下编码,但它不起作用


I give the following coding for delete Row but it is not working

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
   {
       Label Control = (Label)GridView1.Rows[e.RowIndex].FindControl("ITEM");
        connect.cnopen();
       SqlCommand cmd = new SqlCommand("delete from Tempsales where Item='" + Control.Text + "'", connect.cn());
       Bindgrid();
   
   }

推荐答案

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
   {
       Label Control = (Label)GridView1.Rows[e.RowIndex].FindControl("ITEM");
        connect.cnopen();
       SqlCommand cmd = new SqlCommand("delete from Tempsales where Item='" + Control.Text + "'", connect.cn());
   cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            GridView1.dataSource = null;

       Bindgrid();
   
   }


这篇关于如何在asp.net中删除Gridview Row的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆