我想使用ajax和LINQ更新表中的记录 [英] I want to update record in table using ajax and LINQ
本文介绍了我想使用ajax和LINQ更新表中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在ASPX中有这个div: -
I've This div in ASPX :-
<div id="topdiv" class="col-md-8 col-sm-8">
<button id="edittop" runat="server" class="btn btn-success pull-right" type="button" style="border-radius: 50%; height: 50px">
<span class="glyphicon glyphicon-pencil"></span>
</button>
<asp:LinkButton ID="savetop" runat="server" class="btn btn-info pull-right" type="button" Text="Save"
Style="border-radius: 50%; height: 50px" OnClick="savetop_Click">
<span class="glyphicon glyphicon-floppy-save" style="margin-top:10px"></span>
</asp:LinkButton>
<div class="col-md-12 col-sm-6 col-xs-12">
<h3 class="form-inline" style="font-family: 'Century Gothic'; font-size: 25px; font-weight: normal;">
<asp:Label ID="name" runat="server" Text="Name"></asp:Label>
</h3>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="savetop" EventName="Click" />
</Triggers>
<ContentTemplate>
<div class="form-group col-xs-12 col-md-6" style="margin-top: 50px">
<div class="form-inline">
<p>
Age :
<%--<asp:Label ID="Age" runat="server" Text="Label"></asp:Label>--%>
<asp:TextBox ID="Age" runat="server" ReadOnly="true" CssClass="useredit" ClientIDMode="Static" Text="Label"></asp:TextBox>
</p>
</div>
<div class="form-inline">
<p>
Height :
<asp:TextBox ID="Height" runat="server" ReadOnly="true" CssClass="useredit" ClientIDMode="Static" Text="Label"></asp:TextBox>
</p>
</div>
<div class="form-inline">
<p>
Religion :
<asp:TextBox ID="Religion" runat="server" ReadOnly="true" CssClass="useredit" Text="Label"></asp:TextBox>
</p>
</div>
</div>
<div class="form-group col-md-6 col-xs-12 pull-right" style="margin-top: 50px">
<div class="form-inline">
<p>
Working In :
<asp:TextBox ID="Working" ReadOnly="true" runat="server" CssClass="useredit" Text=""></asp:TextBox>
</p>
</div>
<div class="form-inline">
<p>
Living In :
<asp:TextBox ID="Living_In" runat="server" ReadOnly="true" CssClass="useredit" Text=""></asp:TextBox>
</p>
</div>
<div class="form-inline">
<p>
Profession :
<asp:TextBox ID="Profession" runat="server" ReadOnly="true" CssClass="useredit" Text=""></asp:TextBox>
</p>
</div>
</div>
<div class="clearfix"></div>
<div class="form-inline row">
<h4 style="font-family: 'Century Gothic'; font-size: 20px; font-weight: normal">About Me : </h4>
<p>
<asp:TextBox ID="about" runat="server" ReadOnly="true" TextMode="MultiLine" Width="100%" Height="200px" CssClass="useredit" placeholder="Self Description"></asp:TextBox>
</p>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
和脚本的功能如下: -
And Script function as:-
<script type="text/javascript"> //Ajax Function to Save Top Div
$(document).ready(function () {
$('#ContentPlaceHolder1_savetop').click(function () {
var scrptheight = $('#ContentPlaceHolder1_Height').val();
var scrptreligion = $('#ContentPlaceHolder1_Religion').val();
var scrptworking = $('#ContentPlaceHolder1_Working').val();
var scrptlivingin = $('#ContentPlaceHolder1_Living_In').val();
var scrptprofession = $('#ContentPlaceHolder1_Profession').val();
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'loginuser.aspx',
data: "{'Height':'" + scrptheight + "'}","{'Religion':'" + scrptreligion + "'}","{'Working':'" + scrptworking + "'}","{'LingIn':'" + scrptlivingin + "'}","{'Profession':'" + scrptprofession + "'}",
async: false,
success: function (response) {
$('#ContentPlaceHolder1_Height').val(scrptheight);
$('#ContentPlaceHolder1_Religion').val(scrptheight);
$('#ContentPlaceHolder1_Working').val(scrptheight);
$('#ContentPlaceHolder1_Living_In').val(scrptheight);
$('#ContentPlaceHolder1_Profession').val(scrptheight);
alert('Record Saved Successfully');
},
error: function () {
alert("Error");
}
});
});
});
</script>
点击SaveTop按钮我添加了以下代码: -
On Click of SaveTop Button I've added following Code:-
[WebMethod]
[ScriptMethod]
protected void savetop_Click(object sender, EventArgs e)
{
using(SampleDataContext dbContext=new SampleDataContext())
{
try
{
var resulttop = from u in dbContext.User_Informations
join r in dbContext.registers on u.UserName equals r.UserName
select new { r, u };
foreach (var item in resulttop)
{
item.u.UserName = item.r.UserName;
item.r.height = Height.Text.Trim();
item.r.region = Religion.Text.Trim();
item.r.employed = Working.Text.Trim();
item.u.Location = Living_In.Text.Trim();
item.r.profession = Profession.Text.Trim();
item.r.about = about.Text.Trim();
}
dbContext.SubmitChanges();
GetData();
}
catch
{
ClientScript.RegisterStartupScript(this.GetType(), "ErrorMsg", "<script>alert('Can't Update. Report to Support Team')</script>");
}
}
}
Now the problem is , It’s not updating record in table. Please Help...
Now the problem is , It's not updating record in table. Please Help...
推荐答案
(document).ready(function () {
(document).ready(function () {
('#ContentPlaceHolder1_savetop').click(function () {
var scrptheight =
('#ContentPlaceHolder1_savetop').click(function () { var scrptheight =
('#ContentPlaceHolder1_Height').val();
var scrptreligion =
('#ContentPlaceHolder1_Height').val(); var scrptreligion =
这篇关于我想使用ajax和LINQ更新表中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文