Home > Software engineering >  How to add button delete of element Datagridview in webform
How to add button delete of element Datagridview in webform

Time:12-17

 private void LayThongTinHoSo(string sMaDDK)
    {
        try
        {
            DataTable dt = new ReportClass().GetImageList_HOSO_THICONG(sMaDDK);

            foreach (DataRow row in dt.Rows)
            {
                string sFilePath = ResolveUrl("~/"   row["FILENAME"]);
                row["PATH"] = "<img src='"   sFilePath   "' width='400' '"   "' border='0' />";
               
            }

            grdDanhSachHoSo.DataSource = dt;
            grdDanhSachHoSo.DataBind();
        }
        catch (Exception ex)
        {

        }
    }

I have function to list of image , how to add button delete in code in "for each" after element image show ?

the image describe about the function

CodePudding user response:

Recommendation: Don't use GridView to do this. Use dynamic HTML Javascript Ajax to do this.

But if you really want to do this in GridView, here is one of the way that you can do:

<asp:GridView ID="gv1" runat="server" OnRowDeleting="gv1_RowDeleting">
    <Columns>
        <asp:BoundField DataField="Id" HeaderText="Id" />
        <asp:ImageField DataImageUrlField="PATH" HeaderText="Img"></asp:ImageField>
        <asp:CommandField ShowDeleteButton="true" DeleteText="Delete" />
    </Columns>
</asp:GridView>

At the code behind:

protected void gv1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    // do delete
}
  • Related