| |

VerySource

 Forgot password?
 Register
Search
View: 814|Reply: 7

VB.NET developed ASP.NET, CheckBox in DataGrid selected and deleted

[Copy link]

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-4 03:20:01
| Show all posts |Read mode
I did it. But how to delete it? Who can teach the younger brother. . Anxious to do course design!
The selected code is as follows
            Dim i As Integer
            Dim ChBox As CheckBox
            For i = 0 To DataGrid1.Items.Count-1
                ChBox = CType (DataGrid1.Items (i) .Cells (0) .FindControl ("CheckBox1"), CheckBox)
                ChBox.Checked = True
            Next
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-4 08:06:01
| Show all posts
delete from [table] where id = ChBox
Reply

Use magic Report

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-4 10:33:01
| Show all posts
Still not working ... I'm depressed
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-4 16:18:01
| Show all posts
If you want to delete, what else is it selected for?

Don't you know how to operate the database or what? What is the problem?
Reply

Use magic Report

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-4 18:09:01
| Show all posts
I want to select all items. . Then there is a delete button to delete all selected items
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-4 21:51:01
| Show all posts
if you retrive your data from database and store it in dataset

---- get the selectedID, note that the following code only change the data
     in your dataset rather than database
form each row in dataset.table ( "table"). rows
  if row.item ( "id") = selectedID
  row.delete
end if
next

--------- when you click the "submit" botton

dim rowafftected as integer

rowaffected = dataadapter.update (dataset ', "yourTable")
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-5 10:42:01
| Show all posts
public void DelBalanceWayItem (DataGrid dg, string ControlID)
{
foreach (DataGridItem item in dg.Items)
{
CheckBox cb = (CheckBox) item.FindControl (ControlID);
if (cb.Checked)
{
string str = "Update Base_BalanceWay set Status = '1' where ID = '" + dg.DataKeys [item.ItemIndex] .ToString () + "'";
Common.DataBase.DB db = new Common.DataBase.DB ();
db.Execute (str, null, false);
}
}
}
This code may help you
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

Post time: 2020-1-13 14:27:02
| Show all posts
For i = 0 To Me.DataGrid1.Items.Count-1
            Dim ck As CheckBox

            ck = CType (DataGrid1.Items (i) .Cells (0) .FindControl ("CheckBox_delete"), CheckBox)
            If ck.Checked = True Then


                Dim cmd As SqlCommand
                Dim p1 As SqlParameter



                cmd = New SqlCommand ("Article_Delete", conn)
                cmd.CommandType = CommandType.StoredProcedure

                p1 = cmd.Parameters.Add ("@ ArticleId", SqlDbType.Int)
                p1.Value = DataGrid1.Items (i) .Cells (6) .Text

                cmd.ExecuteNonQuery ()

 
   



            End If
        Next
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list