.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> .NET Framework >> Post New QuestionBookmark and Share Subscribe to Forum

Grid View Row deleting

Posted By: Dhilip.R     Posted Date: November 26, 2010    Points:2   Category :.NET Framework
Hi, Experts

When i'm delete a row in a sorted Grid View it will deleting the row of the Grid View, can any body tell me why it is?, i used the following code:


public SortDirection GridViewSortDirection
{
#region Finding SortDirection for Grid View Sorting
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;

return (SortDirection)ViewState["sortDirection"];
}
set { ViewState["sortDirection"] = value; }
#endregion
}

private void SortGridView(string sortExpression, string direction)
{
#region Grid View Sorting
gridviewload();
DataTable dt = new DataTable();
dt = dsrepeter.Tables[0];
DataView dv = new DataView(dt);
dv.Sort = sortExpression + direction;
gvstudent.DataSource = dv;
gvstudent.DataBind();
#endregion
}

protected void gvstudent_OnSorting(Object sender, GridViewSortEventArgs e)
{
#region Finding SortExpression for GridView Sorting
string sortExpression = e.SortExpression;
if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
SortGridView(sortExpression, DESCENDING);
Session["sortExpression"] = sortExpression;
Session["sortDirection"] = DESCENDING;
}
else
{
GridViewSortDirection = SortDirection.Ascending;
SortGridView(sortExpression, ASCENDING);
Session["sortExpression"] = sortExpression;
Session["sortDirection"] = ASCENDING;
}
#endregion
}
protected void gvstudent_SelectedRowDelete(Object sender, GridViewDeleteEventArgs e)
{
#region Delete the selected Row In Gridview
Session["RowIndex"] = e.RowIndex;
if (Session["sortExpression"] != null && Session["sortDirection"] != null)
{
if (gvstudent.Rows.Count > 0)
{
gridviewload();
DataTable dt = new DataTable();
dt = dsrepeter.Tables[0];
DataView dv = new DataView(dt);
sortExpression = Session["sortExpression"].ToString();
direction = Session["sortDirection"].ToString();
dv.Sort = sortExpression + direction;
gvstudent.DataSource = dv;
gvstudent.DataBind();
DataRow dr = dv.Table.Rows[e.RowIndex];
string StDelete = dr["Rollno"].ToString();
repeter.deletestudent(StDelete);
gridviewload();
repeterload();
}
else
{
Response.Write("<script>alert('There is No record To delete')</script>");
gridviewload();
repeterload();
}
}
else
{
gridviewload();
DataTable dt = new DataTable();
dt = dsrepeter.Tables[0];
DataView dv = new DataView(dt);
if (dv.Table.Rows.Count > 0)
{
DataRow dr = dv.Table.Rows[Convert.ToInt32(Session["RowIndex"])];
string StDelete = dr["Rollno"].ToString();
repeter.deletestudent(StDelete);
gridviewload();
repeterload();
}
else
{
Response.Write("<script>alert('There is No record To delete')</script>");
gridviewload();
repeterload();
}
}
gridviewload();
repeterload();
Response.Redirect("index.aspx");
#endregion
}

Thanks & Regards
Dhilip.R

Responses
Author: SureshM             
Posted Date: November 27, 2010     Points: 5   

hi,

I am not clear in the below:

When i'm delete a row in a sorted Grid View it will deleting the row of the Grid View,

--------when u delete a row its deleted. what is wrong here?.



Author: Clintonzz             
Posted Date: May 14, 2014     Points: 20   


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend