所有排在GridView的删除按钮 [英] All Row has a Delete Button in Gridview

查看:96
本文介绍了所有排在GridView的删除按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个简单的页面。 ( EKLE =添加 SIL =删除

和我AVUKAT表是这样的。

简化,当我选择一个下拉MUSTERI和第二下拉AVUKAT,添加数据库(获得HESAP(数字)全自动),或删除数据库和GridView。

这是我的code。

  

添加点击

 保护无效Add_Click(对象发件人,EventArgs的)
    {
        字符串strConnectionString = ConfigurationManager.ConnectionStrings [SqlServerCstr]的ConnectionString。

        SqlConnection的MyConnection的=新的SqlConnection(strConnectionString);
        myConnection.Open();


        字符串hesap = Label1.Text;
        字符串musteriadi = DropDownList1.SelectedItem.Value;
        字符串avukat = DropDownList2.SelectedItem.Value;

        的SqlCommand CMD =新的SqlCommand(INSERT INTO AVUKAT VALUES(@MUSTERI,@AVUKAT,@HESAP),MyConnection的);

        cmd.Parameters.AddWithValue(@ HESAP,hesap);
        cmd.Parameters.AddWithValue(@ MUSTERI,musteriadi);
        cmd.Parameters.AddWithValue(@ AVUKAT,avukat);
        cmd.Connection = MyConnection的;



        SqlDataReader的博士= cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

        /*GridView1.DataSource =博士;
        GridView1.Visible = TRUE; * /
        的Response.Redirect(Request.Url.ToString());
        myConnection.Close();
    }
 

  

删除点击

 保护无效Delete_Click(对象发件人,EventArgs的)
    {
        字符串strConnectionString = ConfigurationManager.ConnectionStrings [SqlServerCstr]的ConnectionString。

        SqlConnection的MyConnection的=新的SqlConnection(strConnectionString);
        myConnection.Open();


        字符串hesap = Label1.Text;
        字符串musteriadi = DropDownList1.SelectedItem.Value;
        字符串avukat = DropDownList2.SelectedItem.Value;

        的SqlCommand CMD =新的SqlCommand(DELETE FROM AVUKAT WHERE MUSTERI = @MUSTERI和AVUKAT = @AVUKAT和HESAP = @HESAP,MyConnection的);

        cmd.Parameters.AddWithValue(@ HESAP,hesap);
        cmd.Parameters.AddWithValue(@ MUSTERI,musteriadi);
        cmd.Parameters.AddWithValue(@ AVUKAT,avukat);
        cmd.Connection = MyConnection的;

        SqlDataReader的博士= cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

        / * GridView1.DataSource =博士;
         GridView1.Visible = TRUE; * /
        的Response.Redirect(Request.Url.ToString());
        myConnection.Close();
    }
 

我的经理希望,删除过程非常辛苦。让我们简单。因为当我想删除一些数据,我必须选择两种DropDownList中,然后删除(SIL)按钮。

我们应该preFER,每行都有一个删除按钮。那么当我们单击按钮。然后必须删除的GridView DATABSE。

我发现完美的例子在互联网上说不上我想要什么。

我想如果我们能做到这一点,南港岛线(删除)按钮应予以删除。

我们如何才能做到这一点?

我觉得 AutoDeleteButton 不这样工作。对?它只是从GridView的删除。不是数据库。但我想删除这两个(GridView的数据库)

解决方案

链接可能对你有用。 另外看看

I have a simple page like this. (EKLE = ADD, SİL = DELETE)

And my AVUKAT Table like this.

Simplify, When i choose first dropdown MUSTERI and second dropdown AVUKAT , add the database (getting HESAP (number) automaticly) or delete the database and gridview.

This is my code.

ADD Click

protected void Add_Click(object sender, EventArgs e)
    {
        string strConnectionString = ConfigurationManager.ConnectionStrings["SqlServerCstr"].ConnectionString;

        SqlConnection myConnection = new SqlConnection(strConnectionString);
        myConnection.Open();


        string hesap = Label1.Text;
        string musteriadi = DropDownList1.SelectedItem.Value;
        string avukat = DropDownList2.SelectedItem.Value;

        SqlCommand cmd = new SqlCommand("INSERT INTO AVUKAT VALUES (@MUSTERI, @AVUKAT, @HESAP)", myConnection);

        cmd.Parameters.AddWithValue("@HESAP", hesap);
        cmd.Parameters.AddWithValue("@MUSTERI", musteriadi);
        cmd.Parameters.AddWithValue("@AVUKAT", avukat);
        cmd.Connection = myConnection;



        SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

        /*GridView1.DataSource = dr;
        GridView1.Visible = true;*/
        Response.Redirect(Request.Url.ToString());
        myConnection.Close();
    }

DELETE Click

protected void Delete_Click(object sender, EventArgs e)
    {
        string strConnectionString = ConfigurationManager.ConnectionStrings["SqlServerCstr"].ConnectionString;

        SqlConnection myConnection = new SqlConnection(strConnectionString);
        myConnection.Open();


        string hesap = Label1.Text;
        string musteriadi = DropDownList1.SelectedItem.Value;
        string avukat = DropDownList2.SelectedItem.Value;

        SqlCommand cmd = new SqlCommand("DELETE FROM AVUKAT WHERE  MUSTERI = @MUSTERI AND AVUKAT = @AVUKAT AND HESAP = @HESAP", myConnection);

        cmd.Parameters.AddWithValue("@HESAP", hesap);
        cmd.Parameters.AddWithValue("@MUSTERI", musteriadi);
        cmd.Parameters.AddWithValue("@AVUKAT", avukat);
        cmd.Connection = myConnection;

        SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

        /* GridView1.DataSource = dr;
         GridView1.Visible = true;*/
        Response.Redirect(Request.Url.ToString());
        myConnection.Close();
    }

My manager wants, delete process is so hard. Let's make easy. Because when i want to delete some data, i must choose two dropdownlist and then delete(Sil) button.

We should prefer that every row has a delete button. Then when we click the button. Then must be deleted gridview AND databse.

I found perfect example on the internet abuot what i want.

I think if we can do that, Sil(Delete) Button should be deleted.

How can we do that?

I think AutoDeleteButton don't work like this. Right? It just deleted from Gridview. Not Database. But i want deleting both (Gridview AND Database)

解决方案

This link might be useful to you. Also have a look at this

这篇关于所有排在GridView的删除按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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