1
Reply

MVC and Jquey table row deleting

aditya immadi

aditya immadi

May 11 2016 12:50 AM
213
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)
{
<tr >
<td>
<input type="hidden" value=@row["id"] id="hdnDelUser" />
<label for="@row["id"]">@row["id"]</label>
</td>
<td>
@row["name"].ToString()
</td>
<td>
@row["email"].ToString()
</td>
<td>
@row["country"].ToString()
</td>
<td>
@row["mobilenumber"].ToString()
</td>
<td>
@row["password"].ToString()
</td>
<td>
@row["expierence"].ToString()
</td>
<td>
@row["functionalarea"].ToString()
</td>
<td>
@row["isactive"].ToString()
</td>
<td>
<input type="button" id="btndel" name="delete" value="Delete" onclick="DeleteUser(this);" />
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 
 
 
 

Answers (1)