How to save list picker selected data in windows phone

359 views Asked by At

Hi i am developing windows phone app. I need to save listpicker selected data to mysql table php. if i save any selected data it will store class name. so i am given below my code.please any one tell me how to solve in this issue.

This is my xaml code

<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>

My C# Code it's retrieve from xml feed

 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;
        }
    }

My Class name

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

    public string ProductName { get; set; }
}

public class BestinukRetailers
{

    public string retailername { get; set; }
}

My C# save data to mysql table using php

        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);

I can save data successfully to database but it will store on class name.I am given below image is i got an out put

enter image description here

This image is when am retrieve selected data i got out put image. so please any one give solution how to save list picker selected data.Advance Thanks..,

1

There are 1 answers

1
Kevin Gosse On BEST ANSWER

The problem is at the line:

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

this.RetailerList.SelectedItem will return the BestinukRetailers object. What you need is the retailername property of that object.

To retrieve it, simply cast the object to its original type:

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