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
Sudhakar
NA
127
2k
please fix this errors on my sample coding
Dec 2 2018 8:43 PM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.Script.Serialization;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using Newtonsoft.Json;
namespace ModelTest
{
public partial class PlayerEntry : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string LoadData(int Flag)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
string query = "select id, name, dob, gender, rating, status, Flag from tbl_Playersname where Flag="+Flag+" order by id desc";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
string jsonvalue = JsonConvert.SerializeObject(dt);
return jsonvalue;
}
[WebMethod]
public static string delete(int id)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
string query = "update tbl_Playersname set Flag=0 where id="+id+"";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
string jsonvalue = "Successfully Deleted!!!";
return jsonvalue;
}
[WebMethod]
public static string adddata(string name, string dob, string gender, string rating, string status)
{
int rating1 = Convert.ToInt32(rating);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
con.Open();
string query = "insert into tbl_Playersname values('" + name + "','" + dob + "','" + gender + "'," + rating1 + ",'" + status + "',"+1+")";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
return "successfully inserted!!!!";
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PlayerEntry.aspx.cs" Inherits="ModelTest.PlayerEntry" %>
<html>
<head runat="server">
<title></title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src=" http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
.auto-style1 {
width: 100%;
}
#name-error {
color: red;
}
#mobile-error {
color: red;
}
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 35%;
height: 15px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
</style>
<script>
$(function () {
$("#datepicker").datepicker(
{ dateFormat: 'dd/mm/yy' })
});
</script>
<script>
function SaveDatas() {
var inputIsValid = $("#validationfrom").valid();
if (inputIsValid == true) {
var name = $('#name').val();
var dob = $('#datepicker').val();
var rating = $('#myRange').val();
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
rating = slider.value;
slider.oninput = function () {
output.innerHTML = this.value;
}
var date = dob;
var d = new Date(date.split("/").reverse().join("-"));
var dd = d.getDate();
var mm = d.getMonth() + 1;
var yy = d.getFullYear();
var newdate = yy + "/" + mm + "/" + dd;
//alert(newdate);
var checkbox = $('#status').is(':checked');
if (checkbox == true) {
var status = 'Active';
}
else {
var status = 'Deactive';
}
var RadioButton1 = $('#rdo1').is(':checked');
if (RadioButton1 == true) {
var gender = 'Male';
}
else {
var gender = 'Female';
}
$.ajax(
{
type: "POST",
url: "PlayerEntry.aspx/adddata",
data: JSON.stringify({ name: name, dob: newdate, gender: gender, rating: rating, status: status }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.d);
},
});
}
else {
alert('Please fill all fields..');
}
}
</script>
<script>
$(document).ready(function () {
$('#validationfrom').validate({ // initialize the plugin
rules: {
name: {
required: true,
},
mobile: {
required: true,
minlength: 10,
maxlength: 10,
number: true
}
},
messages: {
name: "*Please Enter the Name",
mobile: "*Mobile number should by Numeric format only"
}
});
});
</script>
<script>
$.ajax({
type: "POST",
url: "PlayerEntry.aspx/LoadData",
data: JSON.stringify({Flag:1}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var jsonvalue = JSON.parse(msg.d);
$("#pbody").empty();
for (var k = 0; k < jsonvalue.length; k++) {
var id = jsonvalue[k]["id"];
var name = jsonvalue[k]["name"];
var dob = jsonvalue[k]["dob"];
var gender = jsonvalue[k]["gender"];
var rating = jsonvalue[k]["rating"];
var status = jsonvalue[k]["status"];
var appenddata = "<tr><td><input type='Button' id=" + id + " value='Update' onclick='UpdateDate(this.id)'/></td><td><input type='Button' id=" + id + " value='del' onclick='Delete(" + id + ")'/></td><td><input id='name" + id + "' type='text' value=" + name + " /></td><td><input id='dob" + id + "' type='text' value=" + dob + " /></td><td><input id='gender" + id + "' type='text' value=" + gender + " /></td><td><input id='rating" + id + "' type='text' value=" + rating + " /></td><td><input id='status" + id + "' type='text' value=" + status + " /></td></tr>"
$("#pbody").append(appenddata);
}
}
});
</script>
<script>
function Delete(id)
{
$.ajax({
type: "POST",
url: "PlayerEntry.aspx/Delete",
data: JSON.stringify({ id: id }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
},
});
}
</script>
<%-- <script>
$(document).ready(function () {
$.ajax({
type: "POST",
url: "Codepage.asmx/AddData",
data: JSON.stringify({}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var data = data.d;
var h = JSON.parse(data);
$('#tablePROJ1BODY').val('');
for (var i = 0; i < h.length; i++) {
var empid = h[i]['Emp_Id'];
var Emp_Name = h[i]['Emp_Name'];
var Dept = h[i]['Dept'];
var Disg = h[i]['Disg'];
var Salary = h[i]['Salary'];
var tbodydata = "<tr><td><input id='empid" + empid + "' type='text' value=" + empid + " /></td><td><input id='Emp_Name" + empid + "' type='text' value=" + Emp_Name + " /></td><td><input id='Dept" + empid + "' type='text' value=" + Dept + " /></td><td><input id='Disg" + empid + "' type='text' value=" + Disg + " /></td><td><input id='Salary" + empid + "' type='text' value=" + Salary + " /></td><td><input type='Button' id=" + empid + " value='Update' onclick='UpdateDate(this.id)'/></td></tr>"
$('#tablePROJ1BODY').append(tbodydata);
tbodydata = '';
}
},
});
});
</script>
<script>
function UpdateDate(id) {
var empid = $('#empid' + id + '').val();
var Emp_Name = $('#Emp_Name' + id + '').val();
var Dept = $('#Dept' + id + '').val();
var Disg = $('#Disg' + id + '').val();
var Salary = $('#Salary' + id + '').val();
$.ajax({
type: "POST",
url: "Codepage.asmx/UpdateData",
data: JSON.stringify({ empid: empid, Emp_Name: Emp_Name, Dept: Dept, Disg: Disg, Salary: Salary, Condition: id }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('Updated successfully !!!')
},
});
}
</script>--%>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function(){
var favorite = [];
$.each($("input[name='sport']:checked"), function(){
var records = $(this).val();
if(records=="showdeleted")
{
$.ajax({
type: "POST",
url: "PlayerEntry.aspx/LoadData",
data: JSON.stringify({Flag:0}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var jsonvalue = JSON.parse(msg.d);
$("#pbody").empty();
for (var k = 0; k < jsonvalue.length; k++) {
var id = jsonvalue[k]["id"];
var name = jsonvalue[k]["name"];
var dob = jsonvalue[k]["dob"];
var gender = jsonvalue[k]["gender"];
var rating = jsonvalue[k]["rating"];
var status = jsonvalue[k]["status"];
var appenddata = "<tr><td><input type='Button' id=" + id + " value='Update' onclick='UpdateDate(this.id)'/></td><td><input type='Button' id=del" + id + " value='del' onclick='Delete(this.id)'/></td><td><input id='name" + id + "' type='text' value=" + name + " /></td><td><input id='dob" + id + "' type='text' value=" + dob + " /></td><td><input id='gender" + id + "' type='text' value=" + gender + " /></td><td><input id='rating" + id + "' type='text' value=" + rating + " /></td><td><input id='status" + id + "' type='text' value=" + status + " /></td></tr>"
$("#pbody").append(appenddata);
}
}
});
}
});
});
});
</script>
</head>
<body>
<div class="container">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<label><input type="checkbox" value="showall" name="sport" checked="checked"> Show All</label>
<label><input type="checkbox" value="showdeleted" name="sport"> Show Deleted</label>
<button type="button">Get Values</button>
<table id="ptable">
<thead>
<tr>
<th></th>
<th></th>
<th>Player Name</th>
<th>Dob</th>
<th>Gender</th>
<th>Rating</th>
<th>Status</th>
</tr>
</thead>
<tbody id="pbody">
</tbody>
</table>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form id="validationfrom" class="form-horizontal form-label-left">
<div>
<table class="auto-style1">
<tr>
<td>Player Name</td>
<td><input type="text" id="name" name="name" /></td>
</tr>
<tr>
<td>Dob</td>
<td><input type="text" id="datepicker" /></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" id="rdo1" name="gender" value="Male" checked="checked" />Male<br/>
<input type="radio" name="gender" value="Female" />Female<br/>
</td>
</tr>
<tr>
<td>Rating</td>
<td><div class="""slidecontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p><span id="demo"></span></p>
</div></td>
</tr>
<tr>
<td>Status</td>
<td><input type="checkbox" id="Status" name="Status" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" id="btnsubmit" onclick="SaveDatas();"/>
<input type="submit" id="btnclose" value="Close" onclick="model();"/>
<input type="submit" id="btnclear" value="Clear" onclick=""/>
</td>
</tr>
</table>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Attachment:
doubtfile.zip
Reply
Answers (
1
)
Problem with my C# app
How to get Data From Xml Node