TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
tamil priya
NA
164
8k
delete selected row
Feb 7 2018 4:07 AM
how to delete row in this page??
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
static DataTable mytable;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("load_customer", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
mytable = new DataTable();
sda.Fill(mytable);
GridView1.DataSource = mytable;
GridView1.DataBind();
ViewState["dirState"] = mytable;
ViewState["sortdr"] = "Asc";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("~/WebForm2.aspx?");
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string id = GridView1.SelectedRow.Cells[2].Text;
Session["id"] = id;
string name = GridView1.SelectedRow.Cells[3].Text;
Session["name"] = name;
string contact = GridView1.SelectedRow.Cells[4].Text;
Session["contact"] = contact;
string ad = GridView1.SelectedRow.Cells[5].Text;
Session["ad"] = ad;
string ph = GridView1.SelectedRow.Cells[6].Text;
Session["ph"] = ph;
Response.Redirect("~/WebForm2.aspx?Customerid=" + name);
}
protected void GridView1_SelectedIndexChanged(object sender, GridViewDeleteEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
BoundField lbldeleteid = (BoundField)row.FindControl("Customerid");
string constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("delete FROM table_3 where ID='" + Convert.ToInt32(lbldeleteid.Text) + "'", con);
cmd.ExecuteNonQuery();
con.Close();
}
//protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
//{
// //string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
// //SqlConnection con = new SqlConnection(constr);
// //SqlCommand cmd = new SqlCommand("delete from table_3 where Customerid=@Customerid", con);
// //con.Open();
// //mytable.Rows[e.RowIndex].Delete();
// //GridView1.DataSource = mytable;
// //GridView1.DataBind();
// //cmd.ExecuteNonQuery();
// //con.Close();
// //Response.Write("Record DELETED successfully");
// //Response.Redirect("~/WebForm1.aspx");
// //string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
// //SqlConnection con = new SqlConnection(constr);
// //SqlCommand cmd = new SqlCommand("del_customer", con);
// //cmd.CommandType = CommandType.StoredProcedure;
// //mytable.Rows[e.RowIndex].Delete();
// //GridView1.DataSource = mytable;
// //GridView1.DataBind();
// mytable.Rows[e.RowIndex].Delete();
// GridView1.DataSource = mytable;
// GridView1.DataBind();
//}
//protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
//{
// int index1 = Convert.ToInt32(e.CommandArgument);
// GridViewRow row = GridView1.Rows[index1];
// Response.Redirect("~/WebForm2.aspx?RegNo=" + row.Cells[0].Text);
// string constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
// SqlConnection con = new SqlConnection(constr);
// con.Open();
// SqlCommand cmd = new SqlCommand("delete FROM table_3 where Customerid=" + row.Cells[2].Text, con);
// cmd.ExecuteNonQuery();
// Response.Write("Deleted successfully");
// Response.Redirect("WebForm1.aspx");
//}
}
}
Reply
Answers (
0
)
Post back event does not fire after deployment
What is filter in mvc application and custom filter?