Options

webservices : C# Error in visual studio

JoeDoeJoeDoe Member Posts: 11
edited 2011-05-04 in NAV Three Tier
Hello,

I have published the page Contact from the classic client. The main goal is simply to show the content of the contact table on a webpage.

Afterwards, I created a web references (called ContactWebRef) in visual studio for my webservices.
I then created a aspx.cs page with that code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ContactWebRef;

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

    }

    private void LoadContacts()
    {
        ContactWebRef.Contact_Service InstContact = new ContactWebRef.Contact_Service();
       
        InstContact.UseDefaultCredentials = true;

        ContactWebRef.Contact_Service[] Contacts = InstContact.ReadMultiple(null, null, 0);

        GridView1.DataSource = Contacts;

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        LoadContacts();
    }
}

I also created an aspx page with that code :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Ma page de test</title>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h3>Mon test ici</h3>

    <p>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> Website
    </p>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
            onselectedindexchanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Address" HeaderText="Address" 
                    SortExpression="Address" />
            </Columns>
        </asp:GridView>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DB_00ConnectionString %>" 
            SelectCommand="SELECT [Name], [Address] FROM [bii_copy$Contact]">
        </asp:SqlDataSource>

    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </form>
</body>
</html>


When I start debugging, I have only two errors but i don't really know how to solve it.

Error 1 : Cannot implicitly convert type 'ContactWebRef.Contact[]' to 'ContactWebRef.Contact_Service[]' C:\Users\John\Documents\Visual Studio 2010\WebSites\WebSite2\Default2.aspx.cs 22 52 C:\...\WebSite2\

Error 2 : 'ASP.default2_aspx' does not contain a definition for 'GridView1_SelectedIndexChanged' and no extension method 'GridView1_SelectedIndexChanged' accepting a first argument of type 'ASP.default2_aspx' could be found (are you missing a using directive or an assembly reference?) C:\Users\John\Documents\Visual Studio 2010\WebSites\WebSite2\Default2.aspx 18


Can you help me ?

Comments

  • Options
    ufukufuk Member Posts: 514
    ContactWebRef.Contact_Service[] Contacts = InstContact.ReadMultiple(null, null, 0);

    Correct above code as (if Contact is the name of your WS):

    ContactWebRef.Contact Contacts = InstContact.ReadMultiple(null, null, 0);
    Ufuk Asci
    Pargesoft
  • Options
    JoeDoeJoeDoe Member Posts: 11
    Thanks. It works fine now !
    :thumbsup:
  • Options
    sbillysbilly Member Posts: 231
    JOE can u please give me the true code, (after correction)
    :)
    thanks
  • Options
    sbillysbilly Member Posts: 231
    This is my code, there'snt any error but when I execute the page , only the button is visible and there'snt the gridview even when I click on the button

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    
    namespace Vente_à_Crédit
    {
        using webservice;
        
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
            private void LoadCust()
            {
                webservice.Customer_Service srv_cust = new Customer_Service();
                srv_cust.UseDefaultCredentials = true;
                srv_cust.Url = "http://localhost:7047/DynamicsNAV/WS/VenteaCredit/Page/Customer";
                webservice.Customer[] Customers = srv_cust.ReadMultiple(null, null, 100);
                GridView1.DataSource = Customers;
    
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                LoadCust();
            }
        }
    }
    
  • Options
    yukonyukon Member Posts: 361
    Hi Sbilly,

    You left "DataBind" Method.
            GridView1.DataSource = Customers;
            GridView1.DataBind();
    

    Best Regards,
    Yukon
    Make Simple & Easy
Sign In or Register to comment.