- Back to Home »
- Windows store apps C#/XAML »
- Windows store app code to consume web service data to display in gridview
Posted by :
Sudhir Chekuri
Saturday, 14 December 2013
C# code in Web service
[WebMethod]public donardetails Required(string m)
{
SqlCommand cmd = new SqlCommand("select* from tbl_DonateBlood where BloodGroup='" + m + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
List<string> l = new List<string>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string s = ds.Tables[0].Rows[i][0].ToString() + "," + ds.Tables[0].Rows[i][1].ToString() + "," + ds.Tables[0].Rows[i][2].ToString() + "," + ds.Tables[0].Rows[i][3].ToString() + "," + ds.Tables[0].Rows[i][4].ToString();
l.Add(s);
}
donardetails d = new donardetails();
d.details = l;
return d;
}
public class donardetails
{
public List<string> details;
}
XAML Code
<GridView x:Name="Grid_Details" Height="640" >
<GridView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Red" BorderThickness="1" Padding="11">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="SNo:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding SNo}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Name:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Name}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Mobile Number:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding MobileNo}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="Blood Group:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding BloodGroup}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="Location:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding Location}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
</Grid>
</Border>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
<GridView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Red" BorderThickness="1" Padding="11">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="SNo:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding SNo}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Name:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Name}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Mobile Number:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding MobileNo}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="Blood Group:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding BloodGroup}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="Location:" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding Location}" Width="150" Height="25" Foreground="Red" FontSize="15" HorizontalAlignment="Left"/>
</Grid>
</Border>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
C# Code
public async void GetData()
{
Give_Blood.GiveBloodServiceReference.BloodDonarWebServiceSoapClient o = new BloodDonarWebServiceSoapClient();
RequiredResponse a = await o.RequiredAsync(t.Text);
int count = a.Body.RequiredResult.details.Count;
if (t.Text != "bloodgroup")
{
if (count == 0)
{
MessageDialog msg = new MessageDialog("Blood Donars Not Available For '" + t.Text + "' Blood Group");
await msg.ShowAsync();
}
}
string[] rowarr = new string[count];
int k = 1;
for (int i = 0; i < count; i++)
{
string s = a.Body.RequiredResult.details[i];
//string s = a.Body.RequiredResult[i].ToString();
rowarr = s.Split(',');
//rowarr contains a row data
for (int j = 0; j < (rowarr.Length - 1); )
{
tbl_GiveBlood h = new tbl_GiveBlood();
h.SNo = k.ToString();
j++;
h.Name = rowarr[j];
j++;
h.MobileNo = rowarr[j];
j++;
h.BloodGroup = rowarr[j];
j++;
h.Location = rowarr[j];
j++;
k++;
Grid_Details.Items.Add(h);
}
}
}