C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Deleting a row from gridview


Posted Date: 14 Jul 2008      Total Responses: 5

Posted By: Swapneel       Member Level: Bronze     Points: 1



can somebody tell me how to delete a datview row?




Responses

Author: SSN    14 Jul 2008Member Level: GoldRating:     Points: 6

delete selected row from gridview using check box:


protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in grdvUser.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkSelect"); //using the aspx check box
if (cb != null && cb.Checked)
{
string id = row.Cells[1].Text;
cls_busUser.DeleteUser(id);
row.Visible = false;
}
}
}


regards



Author: sandeep    14 Jul 2008Member Level: GoldRating:     Points: 6

hiiii you can use this code.....


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
    <br />
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="UserID" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="UserID" HeaderText="UserID" InsertVisible="False" ReadOnly="True"
SortExpression="UserID" />
<asp:BoundField DataField="Firstname" HeaderText="Firstname" SortExpression="Firstname" />
<asp:BoundField DataField="Lastname" HeaderText="Lastname" SortExpression="Lastname" />
<asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
<asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
<asp:BoundField DataField="Sex" HeaderText="Sex" SortExpression="Sex" />
</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DynacsChatConnectionString2 %>"
DeleteCommand="DELETE FROM [UserTable] WHERE [UserID] = @UserID" InsertCommand="INSERT INTO [UserTable] ([Firstname], [Lastname], [Username], [Password], [Sex]) VALUES (@Firstname, @Lastname, @Username, @Password, @Sex)"
SelectCommand="SELECT * FROM [UserTable]" UpdateCommand="UPDATE [UserTable] SET [Firstname] = @Firstname, [Lastname] = @Lastname, [Username] = @Username, [Password] = @Password, [Sex] = @Sex WHERE [UserID] = @UserID">
<DeleteParameters>
<asp:Parameter Name="UserID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Firstname" Type="String" />
<asp:Parameter Name="Lastname" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="Sex" Type="String" />
<asp:Parameter Name="UserID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Firstname" Type="String" />
<asp:Parameter Name="Lastname" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="Sex" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>



Author: Nimmanagottu Srinivas    14 Jul 2008Member Level: GoldRating:     Points: 6

protected void ProjectTask_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
string i = ProjectTask.DataKeys[e.RowIndex].Value.ToString();
int j = Convert.ToInt32(i);
CRM_ProjectTaskMaster delamobj = new CRM_ProjectTaskMaster(true);
delamobj.Condition = "Delete from project_task where Project_Id=" + j;
DataTable delacc = new DataTable();
delacc = delamobj.SelectByCondition();
loadusers();
Response.Redirect("SearchProjectTask.aspx");
// Page.RegisterStartupScript("Script", "<SCRIPT Language='JavaScript'>alert('Record is deleted');location.replace('Default.aspx');</SCRIPT>");


}
catch (Exception ex)
{
// some error occured. Bubble it to caller and encapsulate Exception object
Page.RegisterStartupScript("Script", "<SCRIPT Language='JavaScript'>alert('Error Occered');</SCRIPT>");
}

}



Author: Sreehari    14 Jul 2008Member Level: SilverRating:     Points: 4

Again some junk codes from some project.Just wondering if copy pasting some code from your current project or something will ever help answering a questions.

To remove a Row from a datagrid view all you require is to call the DeleteRow method in that gridview and pass the Row number that need to be deleted.





Author: Sreehari    14 Jul 2008Member Level: SilverRating:     Points: 3

Just wondering if sandeep could post the connection string as well so that anyone in the world can now access his DB server.

He has posted everying thing other than the connection string



Post Reply
You must Sign In to post a response.
Next : To change images timely as in Dotnetspider
Previous : Reading email through ASP.net application....
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use