>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?');") > >>
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; } } }