Delete confirm() in gride view
-
//file1.aspx <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TxtJobID" runat="server"></asp:TextBox> <asp:TextBox ID="TxtJobTitle" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update" OnClientClick="return confirm('Are You Sure');" Font-Bold="True" /> <br /> <br /> <asp:Label ID="lblMessage" runat="server" Text="Label" Width="474px" style="background-color: #00cccc"></asp:Label><br /> <br /> <asp:DataGrid id="DataGrid1" OnItemCommand="ItemCommand" style="Z-INDEX: 101; LEFT: 175px; TOP: 105px" runat="server" CssClass="tx-tbl-Gr-lml" Width="474px" AllowPaging="true" > <Columns> <asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="Edit"> </asp:ButtonColumn> <asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"> </asp:ButtonColumn> </Columns> </asp:DataGrid><br /> </div> </form> </body> //file1.aspx.cs public partial class _Default : System.Web.UI.Page { OracleConnection cn; OracleCommand cmd; protected void Page_Load(object sender, EventArgs e) { cn = new OracleConnection("data source=dev;user id=hr;password=hr"); if (!Page.IsPostBack) { BindData(); } } void BindData() { string strsql = "select job_id,job_title from jobs"; OracleDataAdapter da = new OracleDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); DataGrid1.DataSource = dt; DataGrid1.DataBind(); } protected void ItemCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if (e.CommandName == "Edit") { FillTheData(e.Item.Cells[2].Text, e.Item.Cells[3].Text); lblMessage.Text = ""; } if (e.CommandName == "Delete") { lblMessage.Text = "Need Code to call confirm() frunction "; } } void FillTheData(string job_id, string job_title) { TxtJobID.Text = job_id; TxtJobTitle.Text = job_title; } protected void Button1_Click(object sender, EventArgs e) { try {
-
//file1.aspx <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TxtJobID" runat="server"></asp:TextBox> <asp:TextBox ID="TxtJobTitle" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update" OnClientClick="return confirm('Are You Sure');" Font-Bold="True" /> <br /> <br /> <asp:Label ID="lblMessage" runat="server" Text="Label" Width="474px" style="background-color: #00cccc"></asp:Label><br /> <br /> <asp:DataGrid id="DataGrid1" OnItemCommand="ItemCommand" style="Z-INDEX: 101; LEFT: 175px; TOP: 105px" runat="server" CssClass="tx-tbl-Gr-lml" Width="474px" AllowPaging="true" > <Columns> <asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="Edit"> </asp:ButtonColumn> <asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"> </asp:ButtonColumn> </Columns> </asp:DataGrid><br /> </div> </form> </body> //file1.aspx.cs public partial class _Default : System.Web.UI.Page { OracleConnection cn; OracleCommand cmd; protected void Page_Load(object sender, EventArgs e) { cn = new OracleConnection("data source=dev;user id=hr;password=hr"); if (!Page.IsPostBack) { BindData(); } } void BindData() { string strsql = "select job_id,job_title from jobs"; OracleDataAdapter da = new OracleDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); DataGrid1.DataSource = dt; DataGrid1.DataBind(); } protected void ItemCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if (e.CommandName == "Edit") { FillTheData(e.Item.Cells[2].Text, e.Item.Cells[3].Text); lblMessage.Text = ""; } if (e.CommandName == "Delete") { lblMessage.Text = "Need Code to call confirm() frunction "; } } void FillTheData(string job_id, string job_title) { TxtJobID.Text = job_id; TxtJobTitle.Text = job_title; } protected void Button1_Click(object sender, EventArgs e) { try {
define your problem rather then code? put your question first and then put the code.
-
//file1.aspx <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TxtJobID" runat="server"></asp:TextBox> <asp:TextBox ID="TxtJobTitle" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update" OnClientClick="return confirm('Are You Sure');" Font-Bold="True" /> <br /> <br /> <asp:Label ID="lblMessage" runat="server" Text="Label" Width="474px" style="background-color: #00cccc"></asp:Label><br /> <br /> <asp:DataGrid id="DataGrid1" OnItemCommand="ItemCommand" style="Z-INDEX: 101; LEFT: 175px; TOP: 105px" runat="server" CssClass="tx-tbl-Gr-lml" Width="474px" AllowPaging="true" > <Columns> <asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="Edit"> </asp:ButtonColumn> <asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"> </asp:ButtonColumn> </Columns> </asp:DataGrid><br /> </div> </form> </body> //file1.aspx.cs public partial class _Default : System.Web.UI.Page { OracleConnection cn; OracleCommand cmd; protected void Page_Load(object sender, EventArgs e) { cn = new OracleConnection("data source=dev;user id=hr;password=hr"); if (!Page.IsPostBack) { BindData(); } } void BindData() { string strsql = "select job_id,job_title from jobs"; OracleDataAdapter da = new OracleDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); DataGrid1.DataSource = dt; DataGrid1.DataBind(); } protected void ItemCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if (e.CommandName == "Edit") { FillTheData(e.Item.Cells[2].Text, e.Item.Cells[3].Text); lblMessage.Text = ""; } if (e.CommandName == "Delete") { lblMessage.Text = "Need Code to call confirm() frunction "; } } void FillTheData(string job_id, string job_title) { TxtJobID.Text = job_id; TxtJobTitle.Text = job_title; } protected void Button1_Click(object sender, EventArgs e) { try {
AJAX has a way to do a confirm. Pretty simple too, and an example found on the AJAX site.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
-
define your problem rather then code? put your question first and then put the code.
the problem is that i want to add confirmation from the user to delete the record when the delete button is pressed in the grid. i have the code to delete the record. Just need help how to call the cofirm() javascript function. and what changes should i make in the code to call the function //file1.aspx <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TxtJobID" runat="server"></asp:TextBox> <asp:TextBox ID="TxtJobTitle" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update" OnClientClick="return confirm('Are You Sure');" Font-Bold="True" /> <br /> <br /> <asp:Label ID="lblMessage" runat="server" Text="Label" Width="474px" style="background-color: #00cccc"></asp:Label><br /> <br /> <asp:DataGrid id="DataGrid1" OnItemCommand="ItemCommand" style="Z-INDEX: 101; LEFT: 175px; TOP: 105px" runat="server" CssClass="tx-tbl-Gr-lml" Width="474px" AllowPaging="true" > <Columns> <asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="Edit"> </asp:ButtonColumn> <asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"> </asp:ButtonColumn> </Columns> </asp:DataGrid><br /> </div> </form> </body> //file1.aspx.cs public partial class _Default : System.Web.UI.Page { OracleConnection cn; OracleCommand cmd; protected void Page_Load(object sender, EventArgs e) { cn = new OracleConnection("data source=dev;user id=hr;password=hr"); if (!Page.IsPostBack) { BindData(); } } void BindData() { string strsql = "select job_id,job_title from jobs"; OracleDataAdapter da = new OracleDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); DataGrid1.DataSource = dt; DataGrid1.DataBind(); } protected void ItemCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if (e.CommandName == "Edit") { FillTheData(e.Item.Cells[2].Text, e.Item.Cells[3].Text); lblMessage.Text = ""; } if (e.CommandName == "Delete") { lblMessage.Text = "Need Code to call confirm() frunction "; } } void FillTheData(string job_id, string job_title) { TxtJobID.Text = job_id; TxtJobTitle.Text = job_title; } protected void Button1_Click(object sender, EventArgs e) { try { string strsql = "Update jobs set job_title="+"'"+TxtJobTitle.Text+"'"+" where job_id="+"'"+TxtJobID.Text+"'"; cmd = new OracleCommand(strsql, cn);
-
//file1.aspx <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TxtJobID" runat="server"></asp:TextBox> <asp:TextBox ID="TxtJobTitle" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update" OnClientClick="return confirm('Are You Sure');" Font-Bold="True" /> <br /> <br /> <asp:Label ID="lblMessage" runat="server" Text="Label" Width="474px" style="background-color: #00cccc"></asp:Label><br /> <br /> <asp:DataGrid id="DataGrid1" OnItemCommand="ItemCommand" style="Z-INDEX: 101; LEFT: 175px; TOP: 105px" runat="server" CssClass="tx-tbl-Gr-lml" Width="474px" AllowPaging="true" > <Columns> <asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="Edit"> </asp:ButtonColumn> <asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"> </asp:ButtonColumn> </Columns> </asp:DataGrid><br /> </div> </form> </body> //file1.aspx.cs public partial class _Default : System.Web.UI.Page { OracleConnection cn; OracleCommand cmd; protected void Page_Load(object sender, EventArgs e) { cn = new OracleConnection("data source=dev;user id=hr;password=hr"); if (!Page.IsPostBack) { BindData(); } } void BindData() { string strsql = "select job_id,job_title from jobs"; OracleDataAdapter da = new OracleDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); DataGrid1.DataSource = dt; DataGrid1.DataBind(); } protected void ItemCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if (e.CommandName == "Edit") { FillTheData(e.Item.Cells[2].Text, e.Item.Cells[3].Text); lblMessage.Text = ""; } if (e.CommandName == "Delete") { lblMessage.Text = "Need Code to call confirm() frunction "; } } void FillTheData(string job_id, string job_title) { TxtJobID.Text = job_id; TxtJobTitle.Text = job_title; } protected void Button1_Click(object sender, EventArgs e) { try {
Hi, You can write the javascript function for the button click....
-
Hi, You can write the javascript function for the button click....
protected void grd_detail_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[4].Attributes.Add("onClick", "return confirm('Are you sure you want to delete the record?');"); } } use this code in event row data bound of grid view
-
the problem is that i want to add confirmation from the user to delete the record when the delete button is pressed in the grid. i have the code to delete the record. Just need help how to call the cofirm() javascript function. and what changes should i make in the code to call the function //file1.aspx <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TxtJobID" runat="server"></asp:TextBox> <asp:TextBox ID="TxtJobTitle" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update" OnClientClick="return confirm('Are You Sure');" Font-Bold="True" /> <br /> <br /> <asp:Label ID="lblMessage" runat="server" Text="Label" Width="474px" style="background-color: #00cccc"></asp:Label><br /> <br /> <asp:DataGrid id="DataGrid1" OnItemCommand="ItemCommand" style="Z-INDEX: 101; LEFT: 175px; TOP: 105px" runat="server" CssClass="tx-tbl-Gr-lml" Width="474px" AllowPaging="true" > <Columns> <asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="Edit"> </asp:ButtonColumn> <asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"> </asp:ButtonColumn> </Columns> </asp:DataGrid><br /> </div> </form> </body> //file1.aspx.cs public partial class _Default : System.Web.UI.Page { OracleConnection cn; OracleCommand cmd; protected void Page_Load(object sender, EventArgs e) { cn = new OracleConnection("data source=dev;user id=hr;password=hr"); if (!Page.IsPostBack) { BindData(); } } void BindData() { string strsql = "select job_id,job_title from jobs"; OracleDataAdapter da = new OracleDataAdapter(strsql, cn); DataTable dt = new DataTable(); da.Fill(dt); DataGrid1.DataSource = dt; DataGrid1.DataBind(); } protected void ItemCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if (e.CommandName == "Edit") { FillTheData(e.Item.Cells[2].Text, e.Item.Cells[3].Text); lblMessage.Text = ""; } if (e.CommandName == "Delete") { lblMessage.Text = "Need Code to call confirm() frunction "; } } void FillTheData(string job_id, string job_title) { TxtJobID.Text = job_id; TxtJobTitle.Text = job_title; } protected void Button1_Click(object sender, EventArgs e) { try { string strsql = "Update jobs set job_title="+"'"+TxtJobTitle.Text+"'"+" where job_id="+"'"+TxtJobID.Text+"'"; cmd = new OracleCommand(strsql, cn);
put the button between span tag. /* */ Regards Keyur Satyadev modified on Thursday, March 12, 2009 8:53 AM