PDA

View Full Version : پر کردن Gridview با Dataset



arioban
سه شنبه 02 آذر 1395, 10:22 صبح
من برای یاد گیری بهتر جاوا دارم این کار رو انجام میدم
در یک وب سایت ازمایشی با زدن کلید یک پاپ آپ باز شده کاربر مشخصات رو وارد میکنه و با زدن دکمه ذخیره این مشخصات در یک گرید ویو در صفحه نمایش داده بشه
مشکل اینجاس که مقدار باز گشتی از وب متد در گرید ویو نمایش داه نمیشه
لطفا راهنمایی کنید

using System;using System.Data;
using System.Web.Services;


namespace Address
{
public partial class Save : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[WebMethod]
public static string NUser(string fname,string lname,Int64 pnumber,string address)
{
DataTable d1 = new DataTable();
DataSet ds1 = new DataSet();
int i = 0;
d1.Columns.Add("FirstName", typeof(string));
d1.Columns.Add("LastName", typeof(string));
d1.Columns.Add("Phonenumber", typeof(Int64));
d1.Columns.Add("address", typeof(string));
d1.Rows.Add();
d1.Rows[i]["FirstName"] = fname;
d1.Rows[i]["LastName"] = lname;
d1.Rows[i]["Phonenumber"] = pnumber;
d1.Rows[i]["address"] = address;
i++;
ds1.Tables.Add(d1);
return ds1.ToString();
}
}
}


<%@ Page Language="C#‎‎" AutoEventWireup="true" CodeBehind="Save.aspx.cs" Inherits="Address.Save" %>

<%@ Import Namespace="System.Data" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 96px;
}


.auto-style2 {
width: 158px;
}


.auto-style3 {
width: 160px;
}


.auto-style4 {
width: 400px;
}
</style>
<script src="Scripts/jquery-3.1.1.js"></script>
<script src="Scripts/jquery-ui-1.12.1.js"></script>


<link rel="stylesheet" href="Content/themes/base/theme.css" />
<link rel="stylesheet" href="Content/themes/base/jquery-ui.css" />
<link rel="stylesheet" href="Content/themes/base/jquery-ui.min.css" />
<script>
$(document).ready(function () {
$('#Button1').click(function () {
$('#popup').dialog({


title: "",
width: 550,
height: 230,
modal: true,
button: {
close: function () {
$(this).dialog('close')
}
}
});
});
$('#Button2').click(function () {
if ($('#Text1').val() == '' || $('#Text2').val() == '' || $('#Text3').val() == '' || $('#Text4').val() == '') {
alert('لطفا مشخصات خود را وارد نمایید');
}
else {
var data = { fname: $('#Text1').val(), lname: $('#Text2').val(), pnumber: $('#Text3').val(), address: $('#Text4').val() };
$.ajax({
type: "POST",
url: "Save.aspx/NUser",
data: JSON.stringify(data),
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (data) {
$('#GridView1').append(data.d);
}
});
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="popup" style="display: none">
<table style="width: 100%;">
<tr>
<td class="auto-style1">FirstName</td>
<td>
<input id="Text1" class="auto-style2" type="text" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="auto-style1">LastName</td>
<td>
<input id="Text2" class="auto-style3" type="text" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="auto-style1">PhoneNumber</td>
<td>
<input id="Text3" class="auto-style3" type="text" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="auto-style1">Address</td>
<td>
<input id="Text4" class="auto-style4" type="text" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="auto-style1">&nbsp;</td>
<td>
<input id="Button2" type="button" value="Save" /></td>
<td>&nbsp;</td>
</tr>
</table>
</div>
<input id="Button1" type="button" value="Click" />
</div>
<div id="GridView">
<br />
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<br />
</div>
</form>
</body>
</html>

vahid-p
سه شنبه 02 آذر 1395, 14:39 عصر
اینجا انجمن جاوا هست، کدی که شما گذاشتید بر اساس .Net نوشته شده که میتونید در انجمن برنامه نویسی مبتنی بر Microsoft .Net Framework (http://barnamenevis.org/forumdisplay.php?81) مطرح کنید.