Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > ปัญหา Windows Phone Show List Data from Web Server (Website)



 

ปัญหา Windows Phone Show List Data from Web Server (Website)

 



Topic : 102987



โพสกระทู้ ( 18 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



ลองเรียกข้อมูลในดาต้าเบสมาแสดงแต่เกิดปัญหา ควรแก้ไขอย่างไร
Code
problem

https://www.thaicreate.com/mobile/windows-phone-show-list-data-from-web-server.html


Code
<phone:PhoneApplicationPage
    x:Class="Train_Guide_Thailand.SearchResultPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="#FF71BAE8">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Margin="10,40,2,10">
            <TextBlock  Text="Treno" Margin="16,-40,10,0" Style="{StaticResource PhoneTextTitle1Style}" FontFamily="Comic Sans MS" Foreground="#FF494943" FontSize="20" Height="23" FontWeight="Bold"/>
            <TextBlock TextWrapping="Wrap" Text="Search result" FontFamily="Comic Sans MS" Foreground="#FF494943" FontSize="26" Height="48" Margin="16,0,0,0"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid Background="LightSkyBlue" x:Name="ContentPanel" CacheMode="BitmapCache" Margin="0,98,0,0" Grid.RowSpan="2">
            <!--<Grid.ColumnDefinitions>
                <ColumnDefinition Width="80*"/>
                <ColumnDefinition Width="81*"/>
                <ColumnDefinition Width="79*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="120*"/>
                <RowDefinition Height="104*"/>
                <RowDefinition Height="112*"/>
                <RowDefinition Height="111*"/>
                <RowDefinition Height="112*"/>
                <RowDefinition Height="111*"/>
            </Grid.RowDefinitions>-->
            
            <!-- FromTo -->
            <TextBlock  FontFamily="Comic Sans MS" Foreground="#FF494943" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Form : " VerticalAlignment="Top" Margin="20,20,0,0" Width="132" Height="28"/>
            <TextBlock  FontFamily="Comic Sans MS" Foreground="#FF494943" HorizontalAlignment="Left" TextWrapping="Wrap" Text="To     : " VerticalAlignment="Top" Margin="20,65,0,0" Height="28" Width="66"/>
            <TextBlock x:Name="formTxt" Text="text1" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Margin="149,20,0,0" Width="300" Height="45"/>
            <TextBlock x:Name="toTxt" Text="text2" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Margin="149,65,0,0" Width="300" Height="42"/>

            <ListBox Margin="10,117,10,10" x:Name="StationList" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Text="{Binding Station_ID}"  TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                            <StackPanel Orientation="Horizontal" Margin="0,0,0,17">
                                <!--<TextBlock Text="{Binding Station_ID}" TextWrapping="Wrap" Margin="5,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/>-->
                                <TextBlock Text="{Binding StationName}" TextWrapping="Wrap" Margin="5,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                                <TextBlock Text="{Binding Latitude}" TextWrapping="Wrap" Margin="5,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                                <TextBlock Text="{Binding Longtitude}" TextWrapping="Wrap" Margin="5,0,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>                    
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>




Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using System.IO.IsolatedStorage;

namespace Train_Guide_Thailand
{
    public partial class SearchResultPage : PhoneApplicationPage
    {

        ProgressIndicator prog;

        public SearchResultPage()
        {
            InitializeComponent();
            

            string url = "http://169.254.80.80/searchData.php";
            Uri uri = new Uri(url, UriKind.Absolute);

            StringBuilder postData = new StringBuilder();
            postData.AppendFormat("{0}={1}", "NULL", HttpUtility.UrlEncode(""));

            WebClient client = default(WebClient);
            client = new WebClient();
            client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            client.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();

            client.UploadStringCompleted += client_UploadStringCompleted;
            client.UploadProgressChanged += client_UploadProgressChanged;

            client.UploadStringAsync(uri, "POST", postData.ToString());

            prog = new ProgressIndicator();
            prog.IsIndeterminate = true;
            prog.IsVisible = true;
            prog.Text = "Loading....";
            SystemTray.SetProgressIndicator(this, prog);
        }

        private void client_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
        {

        }

        private void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {


            if (e.Cancelled == false && e.Error == null)
            {
                MemoryStream ms = new MemoryStream( Encoding.UTF8.GetBytes(e.Result)); 
                ObservableCollection<Station> list = new ObservableCollection<Station>();
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ObservableCollection<Station>));
                
                
                //fuckkkkk
                list = (ObservableCollection<Station>)serializer.ReadObject(ms);

                List<Station> myStation = new List<Station>();

                foreach (Station cm in list)
                {
                    string sStation_ID = cm.Station_ID.ToString();
                    string sStationName = cm.StationName.ToString();
                    string sLatitude = cm.Latitude.ToString();
                    string sLongtitude = cm.Longtitude.ToString();


                    myStation.Add(new Station(sStation_ID, sStationName, sLatitude, sLongtitude));
                }

                this.StationList.ItemsSource = myStation;
                prog.IsVisible = false;
            }

        }

        ////}

        [DataContract]
        public class Station
        {
            [DataMember]
            public string Station_ID { get; set; }

            [DataMember]
            public string StationName { get; set; }

            [DataMember]
            public string Latitude { get; set; }

            [DataMember]
            public string Longtitude { get; set; }

            public Station(string strStation_ID, string strStationName, string strLatitude, string strLongtitude)
            {
                this.Station_ID = strStation_ID;
                this.StationName = strStationName;
                this.Latitude = strLatitude;
                this.Longtitude = strLongtitude;

            }

        }

        //--------show header == Form-To
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string msg1 = "";
            string msg2 = "";
            if (NavigationContext.QueryString.TryGetValue("msg1", out msg1))
            {
                formTxt.Text = msg1;

            }
            if (NavigationContext.QueryString.TryGetValue("msg2", out msg2))
            {
                toTxt.Text = msg2;
            }
        }
        //-----------------------------------------------
    }
}




Tag : Mobile, C#, Windows Phone, Mobile







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-11-23 15:19:27 By : ThanatthaB View : 986 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เข้าใจว่า JSON ที่ถูกส่งมา อาจจะเป็นค่า null หรือผิด format ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-24 11:03:03 By : mr.win
 


 

No. 2



โพสกระทู้ ( 18 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ลองแก้โค้ด จากต้นฉบับแล้วแต่พอเปลี่ยน บรรทัดที่ 090 .this.StationList.ItemsSource = myStation;
แล้วมันerror ค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-24 18:14:18 By : ThanatthaB
 

 

No. 3



โพสกระทู้ ( 18 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ตอนนี้ได้แล้วค่ะ คือต้องออกจาก Emulator ก่อน แล้วStart Debugging ใหม่

ขอบคุญมากนะคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-24 18:32:20 By : ThanatthaB
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ปัญหา Windows Phone Show List Data from Web Server (Website)
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่