مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

arioban

عضویت از 1395/04/01

گرید ویو

  • سه شنبه 2 آذر 1395
  • 12:06
تشکر میکنم

اساتید 

لطفا بگید مشکل این کد ها کجاس

<%@ 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) {
                            if (data.d == "true") {
                                $('#popup').dialog("close");
                            }
                        }
                    });
                }
            });
        });
    </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>

using System;
using System.Data;
using System.Web.Services;
using System.Web.UI.WebControls;

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();
            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++;
            GridView GridView1 = new GridView();
            GridView1.DataSource = d1;
            GridView1.DataBind();
            return "true";
        }
    }
}

پاسخ های این پرسش

تعداد پاسخ ها : 5 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • سه شنبه 2 آذر 1395
  • 12:38

نمیتونید اینکار را انجام دهید

باید گرید را Find کنید

foreach(Control childcontrol in masspage.Controls)   
{
    if(childcontrol is GridView)
    {
        applications = childcontrol as GridView;
    }
    else
    {
        // call this function recursively
    }
}

کاربر سایت

arioban

عضویت از 1395/04/01

  • سه شنبه 2 آذر 1395
  • 12:45

چطور باید این کار رو انجام بدم 

لطفا بیشتر راهنمایی کنید

کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • سه شنبه 2 آذر 1395
  • 12:54

نمونه دادم بهتون

به صورت کدی که دادم FindControl کنید گرید را

کاربر سایت

arioban

عضویت از 1395/04/01

  • سه شنبه 2 آذر 1395
  • 14:19

اقای مدائنی 

این برنامه به این صورت هست که در پاپ آپ مشخصات رو وارد می کنیم و همون مشخصات در گرید ویو صفحه اصلی نمایش داده میشه

ایا آموزشی به غیر از( پیدا کردن کنترل و دسترسی آن از یک صفحه به صفحه دیگر در ASP.Net ) وجود داره 

اگر هست لطفا معرفی کنید

کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • سه شنبه 2 آذر 1395
  • 16:46

این لینک رو ببینید

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)