Click here to Skip to main content
12,630,137 members (27,629 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET C#3.5
Dear Experts,
plz can u suggest me C# code...for delete using checkbox in asp.net using c#..
And also i want to display here name and image.
I tried this code but not cmg..
this is my design page...

<div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="id" DataSourceID="SqlDataSource1">
        <Columns>
        <asp:TemplateField>
        <ItemTemplate>
        <asp:CheckBox ID="chkdelete" runat="server" />
 
        </ItemTemplate>
 
        </asp:TemplateField>
        <asp:BoundField DataField="id" HeaderText="id" />
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Image" HeaderText="Image" />
        </Columns>
 
        </asp:GridView>
 
        <asp:SqlDataSource ID="SqlDataSource1" Runat="server"
    SelectCommand="SELECT id, Name, image FROM showdetails"
    DeleteCommand="DELETE FROM showdetails WHERE id = @id"
    ConnectionString="<%$ ConnectionStrings:sss %>" >
 

</asp:SqlDataSource>
    </div>
    <asp:Button ID="btndelete" runat="server" Text="Delete"
        onclick="btndelete_Click" />
 
    </form>

And My asp.cs page
protected void btndelete_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox checkbox = (CheckBox)row.FindControl("chkdelete");
 

            if (checkbox.Checked)
            {
 
                int id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
                SqlDataSource1.DeleteParameters["id"].DefaultValue = id.ToString();
                SqlDataSource1.Delete();
            }
}
Posted 4-Sep-12 23:09pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Please refer answer for similar question,
Delete rows from datgridview and database access[^]
You will get some help from it, for sure.

[EDIT]

For image in grid have a look:
Display Images In GridView From DataBase Asp.Net[^]
MSDN: Displaying Images in a GridView Column[^]
Displaying Images from a Database in a GridView[^]
  Permalink  
v2
Comments
Member 9376025 5-Sep-12 4:37am
   
i did same code .but i want to display here image in gridview
Prasad_Kulkarni 5-Sep-12 4:39am
   
You want to delete check box selected row or display image in grid?? or both?
Member 9376025 5-Sep-12 4:47am
   
both...
Prasad_Kulkarni 5-Sep-12 4:48am
   
Refer updated answer..
Member 9376025 5-Sep-12 6:43am
   
thanks prasad

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100