Thanks,
Sundeep Podugu
My Blog --------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
basically in my application i want user to remove the any row from gridview and manipulate the rows available in gridview....but the row removed from gridview should not be deleted from database....
basically i was thinkin that by mistake if Admin has a added a row in grdiview then he can remove the row from gridview and continue with the operation on that gridview.
place a Remove button in the itemtemplet so that you can see for each row that button link in the gridview..
you can remove the row from gridview
the code for this is..
public void GridView_RowDeleting(Object sender,
GridViewDeleteEventArgs e)
{
DataTable dt1 = createDataTable();
// Cancel the delete operation if the user attempts to remove
// the last record from the GridView control.if (gv1.Rows.Count <= 1)
{
e.Cancel = true;Response.Write("You must keep at least one record.");
}
else
{
if (gv1.SelectedIndex >= 0)
{
//dt1.Rows.IndexOf(gv1.Selected);
dt1.Rows.RemoveAt(gv1.SelectedIndex);
e.Cancel = false;
gv1.DataSource = createDataSet(dt1);
gv1.DataBind();
gv1.Visible = true;
}
}
}
let me know if you have any question or if you not understand anything in this.
abhishek0410
Participant
1174 Points
932 Posts
how to remove a row from gridview but not from database.
Aug 04, 2008 08:46 AM|LINK
How to remove a row from gridview and not from database
Like i have one gridview and one remove button associated with each row..
now when i click on any row remove button then that row will be removed n shown in gridview but that value will be present in that database...
How to do???
sundeep_38
Contributor
3541 Points
604 Posts
Re: how to remove a row from gridview but not from database.
Aug 04, 2008 02:32 PM|LINK
try gridview.rows[i].visible=false;
Sundeep Podugu
My Blog
--------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
srachuri
Member
323 Points
770 Posts
Re: how to remove a row from gridview but not from database.
Aug 04, 2008 03:32 PM|LINK
if you want to delete perticular row in the gridview..
just Gridview1.Rows[ "rownumber"] .visible = false;
or
you need to deltee at run time?
Let me know
abhishek0410
Participant
1174 Points
932 Posts
Re: how to remove a row from gridview but not from database.
Aug 04, 2008 05:07 PM|LINK
basically in my application i want user to remove the any row from gridview and manipulate the rows available in gridview....but the row removed from gridview should not be deleted from database....
srachuri
Member
323 Points
770 Posts
Re: how to remove a row from gridview but not from database.
Aug 04, 2008 05:11 PM|LINK
As per I know if you bind the data gridview if your trying to remove the row from Gridview it will not remove from the database..
if will remove only from the gridview..
other wise you can false visibility of that row..
let me know if you have any questions..
abhishek0410
Participant
1174 Points
932 Posts
Re: how to remove a row from gridview but not from database.
Aug 04, 2008 05:28 PM|LINK
cv_vikram
Star
8510 Points
1056 Posts
Re: how to remove a row from gridview but not from database.
Aug 04, 2008 05:42 PM|LINK
Yes the data will not removed from the database until and unless you are explicetly calling the databsase function to delete them from the database.
This can be beneficial to other community members reading the thread.
abhishek0410
Participant
1174 Points
932 Posts
Re: how to remove a row from gridview but not from database.
Aug 04, 2008 05:46 PM|LINK
So could you plz tell me how to do.???i am giving a link button in template which i call as "Remove"
srachuri
Member
323 Points
770 Posts
Re: how to remove a row from gridview but not from database.
Aug 04, 2008 05:56 PM|LINK
Yes you can put link button.. if you clikc that buttong it should ask permision that you need to remove the row from the data grid
allow me few min I will send you code I am busy now little bit I will send you as soon as I can..
srachuri
Member
323 Points
770 Posts
Re: how to remove a row from gridview but not from database.
Aug 04, 2008 06:06 PM|LINK
place a Remove button in the itemtemplet so that you can see for each row that button link in the gridview..
you can remove the row from gridview
the code for this is..
public void GridView_RowDeleting(Object sender, GridViewDeleteEventArgs e){
DataTable dt1 = createDataTable(); // Cancel the delete operation if the user attempts to remove // the last record from the GridView control.if (gv1.Rows.Count <= 1){
e.Cancel = true;Response.Write("You must keep at least one record.");}
else{
if (gv1.SelectedIndex >= 0){
//dt1.Rows.IndexOf(gv1.Selected);dt1.Rows.RemoveAt(gv1.SelectedIndex);
e.Cancel = false;gv1.DataSource = createDataSet(dt1);
gv1.DataBind();
gv1.Visible = true;}
}
}
let me know if you have any question or if you not understand anything in this.