I have a asp.net grid view which has a buttonfield to reset a user? I need to call a js function to get a confirmation message, when the buttonfield clicks, Any ideas? TIA
here is my grid view
<asp:GridView ID="grdAllProducts" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" OnRowCommand="grdAllProducts_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="USER_ID" HeaderText="User ID" />
<asp:BoundField DataField="USER_NAME" HeaderText="User Name" />
<asp:BoundField DataField="EMAIL" HeaderText="E-mail" />
<asp:BoundField DataField="PHONE_NUMBER" HeaderText="Phone No." />
<asp:BoundField DataField="USER_ROLE_NAME" HeaderText="User Role" />
<asp:ButtonField ButtonType="Button" Text="Reset" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
here is my js function
function validateResetButton() {
if (confirm('Are you sure you want to Reset this User?')) {
return true;
}
else {
return false;
}
}
2
Answers
This works for me…
Add commandname in buttonfield
Add rowdatabound to gridview control
in most cases, it MUCH easer to just drop in a regular plain jane button.
So, say we have this simple GV.
And code to load:
And we now have this:
So, lets now add a click event to the button.
so, we have now this:
And our code behind click event?
Say this: