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 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsForums
Top experts
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Bhuvanesh MohankumarRank #310 · 8.1K reputationPosted May 10, 2016, 9:42 PM EDT
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