TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
aditya immadi
NA
215
23.8k
MVC and Jquey table row deleting
May 11 2016 12:50 AM
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
Reply
Answers (
1
)
Run cmd Commands from C# Code
send email with password protected pdf