954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Delete Row on Buuton Click in C# through coding

Delete selected record on Button click. I am using MS Access as a Database in C#.
How it can be done ??

abhi10kumar
Junior Poster
126 posts since Feb 2011
Reputation Points: 15
Solved Threads: 1
 
string code;
            code = textBox.Text;
            r = dp.Tables[Tablename].Rows.Find(code);
            r.Delete();
            db.Update(dp);


r is datarow.
dp is dataset
db is dataAdapter.

You can find the row that u want to delete by entering a column name.
And then this code would delete that row and would also update your table.

ajinkya112
Light Poster
47 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Perhaps this thread http://www.daniweb.com/forums/thread335414.html and what adatapost says in it can help you?

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 
#Aspx Page
#-----------
# This is the template filed of the grid view... Grid view template column for the check boxk
<asp:TemplateField HeaderText="Select">
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkSelect" runat="server" />
                                            </ItemTemplate>
                                        </asp:TemplateField>

# button
<asp:Button ID="btnDelete" runat="server" Text="Delete" Width="10%" OnClick="btnDelete_Click1" />


#Code
#------------
 
protected void btnDelete_Click1(object sender, EventArgs e)
    {
        
        foreach(GridViewRow row in GridView1.Rows)
        {

            CheckBox cb = (CheckBox)row.FindControl("chkSelect");

            if (cb.Checked && cb != null)
            {

                int ID_No= Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
                		
		# Make query for Deleting Row form Category ID  example : delete * from table where id=ID_No               
		
               
            }
        }
		
	# Rebind Grid View Here.
       

    }

Regards,
jay

jay.gadhavi
Newbie Poster
9 posts since Feb 2011
Reputation Points: 8
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: