Click here to Skip to main content
15,909,939 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to display name in alert box and then display that name with its id in another alert box by clicking ok button of alert box in the format of grid view with having property to update or delete within gridview. Any body have a solution so please provide
Posted
Updated 25-Oct-13 0:16am
v2
Comments
Bajirao_ 25-Oct-13 3:14am    
What you have tried? elaborate requirement more.
Masroor Ansari 25-Oct-13 6:17am    
Just a question

1 solution

Hello Masroor,

If I understand your question correctly then please refer to this[^] article. It shows how to do INSERT/UPDATE using a gridview.

Now lets assume that you want to confirm the delete operation by first displaying the name, followed by another confirm showing the name and the id. In that case you can hook up following JavaScript function.
JavaScript
function confirmDelete(strName, strId) {
    var r = confirm("Will delete " + strName);
    if (r == true) {
        r = confirm("Will delete record having id " + strId + " and name " + strName);
        if (r == true) return true;
    }
    return false;	
}

The javascript wiring will be done in RowDataBound event of the gridview. So do remove the onClientClick code from the aspx file shown in above article. The wiring up code in your code behind will be something like one shown below.
C#
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e ) {
    try {
        if (e.Row.RowType == DataControlRowType.DataRow) {
            DataRowView drEachRow = (DataRowView) e.Row.DataItem;
            LinkButton lbBind= (LinkButton )e.Row.FindControl("lnkRemove");
            lbBind.Attributes.Add("onclick", "javascript:return confirmDelete('" + DataBinder.Eval(e.row.DataItem, "ContactName") +
                                        "', '" + DataBinder.Eval(e.row.DataItem, "CustomerID") + "');");
        }
    }
    catch(Exception objExp) {
        // handle exception
    }
}

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900