您好我正在开发Windows手机应用程序。我需要将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);
我可以将数据成功保存到数据库,但它会存储在类名上。我在下面给出的图像是我有一个输出
这张图片是我检索所选数据的时间。所以请任何人给出解决方案如何保存列表选择器选择的数据。高级谢谢..,
答案 0 :(得分: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));