0

嗨,我正在开发 Windows Phone 应用程序。我需要将 listpicker 选择的数据保存到 mysql 表 php。如果我保存任何选定的数据,它将存储类名。所以我在下面给出了我的代码。请任何人告诉我如何解决这个问题。

这是我的 xaml 代码

<toolkit:ListPicker x:Name="RetailerList" ItemsSource="{Binding Retailerslist}" Foreground="Black" BorderThickness="0"  Margin="30,-1,39,0" >
      <toolkit:ListPicker.ItemTemplate>
             <DataTemplate>
                  <TextBlock Text="{Binding retailername}" FontSize="20" FontFamily="Arial"  Foreground="Black"  TextWrapping="Wrap" />
              </DataTemplate>
      </toolkit:ListPicker.ItemTemplate>
 </toolkit:ListPicker>

我的 C# 代码是从 xml 提要中检索的

 Producttype = articles.Element("Retailers").Elements("Retailer") 
                .Select(retail => new BestinukRetailers                                    
                {  
                   retailername = retail.Attribute("name").Value
                }).ToList(),


   protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        string selectedIndex = "";
        if (NavigationContext.QueryString.TryGetValue("scustomerID", out selectedIndex))
        {
            RetailerList.ItemsSource = App.ProductList.Producttype;
        }
    }

我的班级名称

public class BestinukProduct
{
    public List<BestinukRetailers> Producttype { get; set; }

    public string ProductName { get; set; }
}

public class BestinukRetailers
{

    public string retailername { get; set; }
}

我的 C# 使用 php 将数据保存到 mysql 表

        string url = "http://www.best.com/Best_Windows/insert.php";
        Uri uri = new Uri(url, UriKind.Absolute);


        StringBuilder postData = new StringBuilder();
        postData.AppendFormat("{0}={1}", "product_id", HttpUtility.UrlEncode(ProductDetails.productId));
        postData.AppendFormat("&{0}={1}", "customer_id", HttpUtility.UrlEncode(LoginPage.strcustomer_id_k));

        postData.AppendFormat("&{0}={1}", "retailer",HttpUtility.UrlEncode(this.RetailerList.SelectedItem.ToString()));

        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_SaveUploadStringCompleted;
        client.UploadProgressChanged += client_SaveUploadProgressChanged;

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

        prog = new ProgressIndicator();
        prog.IsVisible = true;
        prog.Text = "Connecting update to server....";
        SystemTray.SetProgressIndicator(this, prog);

我可以成功地将数据保存到数据库,但它会存储在类名中。我在下面给出的图像是我得到了一个输出

在此处输入图像描述

此图像是当我检索所选数据时,我得到了放置图像。所以请任何人提供解决方案如何保存列表选择器选择的数据。提前谢谢..,

4

1 回答 1

0

问题在于:

postData.AppendFormat("&{0}={1}", "retailer",HttpUtility.UrlEncode(this.RetailerList.SelectedItem.ToString()));

this.RetailerList.SelectedItem将返回BestinukRetailers对象。您需要的是该retailername对象的属性。

要检索它,只需将对象转换为其原始类型:

var retailer = (BestinukRetailers)this.RetailerList.SelectedItem;
postData.AppendFormat("&{0}={1}", "retailer",HttpUtility.UrlEncode(retailer.retailername));
于 2013-08-27T12:53:51.300 回答