Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grid View - DELETE CommandField
Message
Information générale
Forum:
ASP.NET
Catégorie:
WebForms
Divers
Thread ID:
01335798
Message ID:
01335804
Vues:
12
>Hi all,
>
>How can I find the id of the Delete CommandField set as ButtonType = Image ? I am trying to add the DELETE confirmation:
>
>
>Protected Sub gvUsers_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvUsers.RowDataBound
>
>        Dim ib As ImageButton = DirectCast(e.Row.FindControl("Delete"), ImageButton)
>
>
>        ib.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete this item?');")
>
>
>
>Thank you,
>Daniel

Here is the code I have, you would need to translate into VB.NET
ImageButton btnDelete = (ImageButton)e.Row.Cells[1].Controls[0];
//For command buttons we need to use Cells, we can not use FindControl
protected void ProfilesGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            DataRowView view = e.Row.DataItem as DataRowView;
            // http://forums.asp.net/p/1183536/2016125.aspx - to make fixed width

            for (int i = 4; i < e.Row.Cells.Count; i++)
            {
                e.Row.Cells[i].Attributes.Add("style", "word-wrap:break-word;width:70px");
            }           
            

            string PersonName = view["FirstName"].ToString() + " " + view["LastName"].ToString(); 
            if (this.ddlApprovedStatus.SelectedIndex == 0)
            {
                ImageButton btnDelete = (ImageButton)e.Row.Cells[1].Controls[0];
                if (btnDelete != null)
                {
                    btnDelete.ToolTip = "Delete " + PersonName;
                    btnDelete.Attributes.Add("onClick",
                        "var ch=confirm('Do you want to delete " +
                        PersonName + "?');if(ch==false) return false;");
                }
            }
            ImageButton btnEdit = (ImageButton)e.Row.Cells[0].Controls[0];
            if (btnEdit != null)
                btnEdit.ToolTip = "View Info for " + PersonName;

            CheckBox chkButton = e.Row.FindControl("chkApproved") as CheckBox;
            if (chkButton != null)
            {
                if (this.ddlApprovedStatus.SelectedIndex == 0)
                {
                    chkButton.ToolTip = "Approve " + PersonName;
                    string JScript = "var btn = document.getElementById('" +
                                     this.bntApprove.ClientID + @"')
                                     if (btn)
                                        { //alert('CheckBox Clicked');
                                          btn.disabled = false;}";
                    chkButton.Attributes.Add("OnClick", JScript);  
                    chkButton.Enabled = true;
                }
                else
                    chkButton.Enabled = false;
            }
        }
    }
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform