Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a database having Isdeleted field and datatype is bit i want to change the bit value on button click in gridview and also want to hide that row from gridview unless i set that Isdeleted field to false?

pls help
Posted
Updated 2-Jan-15 22:49pm
v2
Comments
Tejas Vaishnav 5-Jan-15 0:58am    
Is my solution, work for you? then please accept it as solution so it will help other who are facing same issue. And don't forget to rate it.

1 solution

1) first of all make modification on your select data query for gridview to display only those records which having IsDeleted = false

SQL
select......
.........
Where IsDeleted = 0


2) second create a web method which will called by clicking on your gridview's button click, and that web method is responsible to change your database table record related to Is Delete flag. call that web method using jquery ajax call, and on sucess of ajax call, find your gridview row and set it's css property to display none or something like that to hide the row.

C#
[System.Web.Services.WebMethod]
public static string SetIsDeleted(string id)
{
    //Write your logic to update database entry with IsDeleted flag to false (0)
}


JavaScript
<script type = "text/javascript">
var id = 1; --write your own logic to get id for which you need to set IsDeleted flag
function ShowCurrentTime() {
    $.ajax({
        type: "POST",
        url: "Default.aspx/SetIsDeleted",
        data: '{id: "'+ id  + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function(response) {
            alert(response.d);
        }
    });
}
function OnSuccess(response) {
    //write logic to display none your grid view row
}


</script>


please check link[^] to check how to define and consume web method of aspx page.

Also please check this Link[^] too, that article is demonstrating how to delete record from gird view as well as database, you just need to follow all the steps and change logic just like instead of deleting record you need to write your query in such a way to just set IsDeleted column value.
 
Share this answer
 
v5

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