I need to put an alert from code-behind on certain conditions.
Please help me out -
My aspx page and aspx.cs code are as follows -
<asp:GridView ID="grdEmployeeDetails" runat="server" AutoGenerateColumns="false" Width="100%">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Employee Name" HeaderText="Name" />
<asp:BoundField DataField="Salary" HeaderText="Salary" " />
<asp:BoundField DataField="Dept" HeaderText="Department" />
<asp:BoundField DataField="Desig" HeaderText="Designation />
</Columns>
<HeaderStyle Width="60px" Height="50px" />
<RowStyle Width="200px" />
</asp:GridView>
<div>
<asp:Button ID="btnYes" runat="server" Text="yes"
OnClick="btnYes_Click" />
<asp:Button ID="btnNot" runat="server" Text="No"
OnClick="btnNo_Click" />
</div>
-------------
aspx.cs -
btnYes_ClickEvent -
{
Int32 totalCount = grdGetAsset.Rows.Cast<GridViewRow>().Count(r => ((CheckBox)r.FindControl("chkRow")).Checked);
if (totalCount > 0)
{
string message = "Do you want to Submit?";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("return confirm('");
sb.Append(message);
sb.Append("');");
ClientScript.RegisterOnSubmitStatement(this.GetType(), "alert", sb.ToString());
// here if user clicks "Yes" , then proceed further. Else No
// How to check which button user have clicked ??
}
}
--
Logic is -
1. System will check how many rows are selected (checkbox in gridview).
2. If number of rows selected is more than zero ; then the user will click on "Yes" button
3. On "Yes" button click - the system will ask -"Are you sure these are correct details" ?
4. Check if user have clicked on "OK" or "Cancel" button. If "OK" - proceed with update query. If "Cancel" - do nothing.
-----
Please guide ... its urgent,
Bhuvanesh MohankumarPosted May 11, 2016, 12:44 PM
Nataraj Gandhi ArunachalamPosted May 11, 2016, 7:00 PM
Bhuvanesh MohankumarPosted May 11, 2016, 12:52 PM