Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear team,
i wanted to delete the row data from the grid view but it should be deleted from grid view .it shouldn't reflect on database means it shouldn't deleted on database and active flag condition would be false if data delete else true if it wont deleted
looking forward to hearing from you guys.
Thank
Posted

1 solution

For this, Logic can be following :

1. Firstly take dataset from database to c# datatable.

2. Bind gridview from datatable(Bind only active record by using datatable.select() method) and keep this datatable in a viewstate/session.

3. Now perform task for active/Inactive in gridview and update datatable that exists in viewstate/session then again bind it to gridview and again keep this datatable in same viewstate/session.
.
 
Share this answer
 
v5
Comments
Dheeraj Mishra 30-Dec-15 0:44am    
can you provide the code snippets

my code is here--


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AccountLogin;
using System.Data;
using RKLib.ExportData;

public partial class adminlogin_Holiday : System.Web.UI.Page
{

DataTable FromTable = new DataTable();
string user_role_id, empid, formid = "";
holidays holi = new holidays();

protected void Page_Load(object sender, EventArgs e)
{
if (Session["User_Role_ID"] != null)
{
if (Session["EmpID"] != null)
{
if (Session["FormID"] != null)
{
user_role_id = Session["User_Role_ID"].ToString();
empid = Session["EmpID"].ToString();
formid = Session["FormID"].ToString();
}
}
}
else
{
Response.Redirect("~/login.aspx");
}

if (!IsPostBack)
{
BindData();
}

if (user_role_id.ToString() != "1000")
{
gd.FooterRow.Visible = false;
gd.Columns[4].Visible = false;

}

}
protected void gd_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{


gd.EditIndex = -1;
BindData();

}
protected void gd_RowDeleted(object sender, GridViewDeleteEventArgs e)
{
Label Tag_id = (Label)gd.Rows[e.RowIndex].FindControl("lbl_id1");
string Tagid = Tag_id.Text;
AccountLoginClient client = new AccountLoginClient();
DataSet ds = new DataSet();

try
{
client.Open();
ds = client.Deleteholidays(Tag_id.Text);

client.Close();
}
catch (Exception ex)
{ }
finally
{
ds.Dispose();
BindData();
}

}



#region Bind Data

protected void BindData()
{
AccountLoginClient client = new AccountLoginClient();
DataSet ds = new DataSet();
try
{
client.Open();
ds = client.Selectholidays1();
FromTable = ds.Tables[0];

if (FromTable.Rows.Count > 0)
{
gd.DataSource = FromTable;

gd.DataBind();
}
else
{
FromTable.Rows.Add(FromTable.NewRow());
gd.DataSource = FromTable;
gd.DataBind();

int TotalColumns = gd.Rows[0].Cells.Count;
gd.Rows[0].Cells.Clear();
gd.Rows[0].Cells.Add(new TableCell());
gd.Rows[0].Cells[0].ColumnSpan = TotalColumns;
gd.Rows[0].Cells[0].Text = "No Record Found";
}
}

catch (Exception ex)
{ }
finally
{
ds.Dispose();
client.Close();
}


}
#endregion

protected void gd_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
AccountLoginClient client = new AccountLoginClient();

try
{
client.Open();
Label emp_id = (Label)gd.Rows[e.RowIndex].FindControl("lbl_id");

TextBox Edit_year = (TextBox)gd.Rows[e.RowIndex].FindControl("txtedityear");
TextBox Edit_day = (TextBox)gd.Rows[e.RowIndex].FindControl("txteditday");
TextBox Edit_description = (TextBox)gd.Rows[e.RowIndex].FindControl("txteditDescription");
TextBox Edit_type = (TextBox)gd.Rows[e.RowIndex].FindControl("txtedittype");

holi.id = emp_id.Text;
holi.year = Edit_year.Text;
holi.day = Edit_day.Text;

holi.description = Edit_description.Text;
holi.type = Edit_type.Text;
client.Updateholidays(holi);
client.Close();

}
catch (Exception err)

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