Hai all i wrote thiss code for deleting users but my problem is when i m tryning to deleting 10th record or something like that it does not corresponding row that is insteadd of delting 1th record it deletes 1st row and next time it ll delete 2 nd row viceversa ..i found that it il delting recods from ascending order of id.here is my code can anyone one help me with this
in my view
function DeleteUser() {
// var DelUser = $('input[type=hidden]').val();
var DelUser = $("#hdnDelUser").val();
alert(DelUser);
$.ajax({
url: '/Admin/DeleteUser',
type: "GET",
datatype: "JSON",
data: { UID: DelUser },
success: function (s) {
alert("deleted successfully");
@foreach (DataRow row in dtViewUsers.Rows)
{
@row["name"].ToString()
@row["email"].ToString()
@row["country"].ToString()
@row["mobilenumber"].ToString()
@row["password"].ToString()
@row["expierence"].ToString()
@row["functionalarea"].ToString()
@row["isactive"].ToString()
and in my home controller and Dal like this
public ActionResult DeleteUser(string UID)
{
int UserID = v.DelUser(UID);
return Json(UserID, JsonRequestBehavior.AllowGet);
}
internal int DelUser(string UID)
{
int i=0;
SqlConnection con=new SqlConnection(s);
SqlCommand cmd = new SqlCommand("Sp_DelUser", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.NVarChar)).Value = UID;
con.Open();
object obj = cmd.ExecuteScalar();
if (obj != null)
{
i = (int)obj;
}
return i;
}
TIA
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bhuvanesh MohankumarPosted May 11, 2016, 1:42 AM
Hi,
You have an option to hold teh row Id value in hidden filed.
value=@row["id"] id="hdnDelUser" />
Better, use the following code get the row ID field and send to teh delete function.
or use the "remove()" function of Jquery