how can i change the repeater's label value from code behind

user3997016

i have the following code Default.aspx

 <asp:Repeater ID="rpt" runat="server" >

 <ItemTemplate>


  <asp:Label ID="lbllat" runat="server" Text='<%#Eval("LAT")%>'></asp:Label>

  <asp:Label ID="lbllon" runat="server" Text='<%#Eval("LON")%>'></asp:Label>

  <asp:Label ID="lbladdress" runat="server"></asp:Label>

  </ItemTemplate>

   </asp:Repeater>

Default.aspx.cs

DataSet ds = new DataSet();
            ds = cls.ReturnDataSet("fetch_data)",
                 new SqlParameter("@Field", "*"),
                 new SqlParameter("@TblNm", "gps_data"));


            rpt.DataSource = ds;
            rpt.DataBind();


     for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {

            String address = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + ds.Tables[0].Rows[0]["LAT"].ToString() + "," + ds.Tables[0].Rows[0]["LON"].ToString() + "&sensor=false";
            var json = new WebClient().DownloadString(address);
            String formatted_address = Regex.Match(json, @"(?s)""formatted_address""\s*:\s*""(.+?)""").Groups[1].Value;

            foreach (RepeaterItem item in rpt.Items)
            {
                Label lab = item.FindControl("lbladdress") as Label;
                lab.Text = formatted_address.ToString();
            }
        }

From above code i am able to fetch latitude and longitude but after that when i fetch the address from latitude and longitude then it will fetch all the address of different latitude and longitude but it is set address of last latitude and longitude address.

so i am seeing the same address on all records instead of different addresses.

how can i set address according to their latitude and longitude .?

Angus Chung

You should modify your code in this way:

Before

String address = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + ds.Tables[0].Rows[0]["LAT"].ToString() + "," + ds.Tables[0].Rows[0]["LON"].ToString() + "&sensor=false";

foreach (RepeaterItem item in rpt.Items)
{
    Label lab = item.FindControl("lbladdress") as Label;
    lab.Text = formatted_address.ToString();
}

After

String address = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + ds.Tables[0].Rows[i]["LAT"].ToString() + "," + ds.Tables[0].Rows[i]["LON"].ToString() + "&sensor=false";

RepeaterItem item = rpt.Items[i];
Label lab = item.FindControl("lbladdress") as Label;
lab.Text = formatted_address.ToString();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get a value from Repeater in code-behind

From Dev

How to Fill Repeater ItemTemplate from Code Behind?

From Dev

How to get Reference to the label in repeater item in code behind

From Dev

How to get Footer Item value on code behind with nested Repeater?

From Dev

How to add Repeater control dynamically from code behind?

From Dev

How to call javascript from code behind for Repeater control

From Dev

How can i update hidden field value on one page from the code behind of another page?

From Dev

How to change a label's color that is present in a repeater on its Onload function?

From Dev

How can I access my ViewModel from code behind

From Dev

How can I access the images folder from code behind

From Dev

Can't Change CssClass From Code Behind

From Dev

How can I change default position of label with value in input range?

From Dev

How can I change an input for a label without an error in value in Angular?

From Dev

How to change label font in code behind using c#

From Dev

Assigning value to the label which is inside gridview from code behind

From Dev

I want to get drowpdown value from repeater in code how to get it in asp.net?

From Dev

How to change visualstate from code behind?

From Dev

How to change visualstate from code behind?

From Dev

Can I change Jquery-ui active tab on button click from code behind?

From Dev

How to pass a value from JavaScript to code behind?

From Dev

How to update label from callback function in code behind?

From Dev

How can I force a TextBox's DataSource to update after a change in value through code?

From Dev

How can I force a TextBox's DataSource to update after a change in value through code?

From Dev

How to get the value of "Label" inside the repeater?

From Dev

How to get the value of "Label" inside the repeater?

From Dev

How can I change the output of a label, based on what's selected from a dropdown list (C# in ASP.NET)

From Dev

How can php change label html value?

From Dev

how can i add h3 code from asp.net behind code?

From Dev

Transfer value from code behind in xaml page to change expander foreground

Related Related

  1. 1

    Get a value from Repeater in code-behind

  2. 2

    How to Fill Repeater ItemTemplate from Code Behind?

  3. 3

    How to get Reference to the label in repeater item in code behind

  4. 4

    How to get Footer Item value on code behind with nested Repeater?

  5. 5

    How to add Repeater control dynamically from code behind?

  6. 6

    How to call javascript from code behind for Repeater control

  7. 7

    How can i update hidden field value on one page from the code behind of another page?

  8. 8

    How to change a label's color that is present in a repeater on its Onload function?

  9. 9

    How can I access my ViewModel from code behind

  10. 10

    How can I access the images folder from code behind

  11. 11

    Can't Change CssClass From Code Behind

  12. 12

    How can I change default position of label with value in input range?

  13. 13

    How can I change an input for a label without an error in value in Angular?

  14. 14

    How to change label font in code behind using c#

  15. 15

    Assigning value to the label which is inside gridview from code behind

  16. 16

    I want to get drowpdown value from repeater in code how to get it in asp.net?

  17. 17

    How to change visualstate from code behind?

  18. 18

    How to change visualstate from code behind?

  19. 19

    Can I change Jquery-ui active tab on button click from code behind?

  20. 20

    How to pass a value from JavaScript to code behind?

  21. 21

    How to update label from callback function in code behind?

  22. 22

    How can I force a TextBox's DataSource to update after a change in value through code?

  23. 23

    How can I force a TextBox's DataSource to update after a change in value through code?

  24. 24

    How to get the value of "Label" inside the repeater?

  25. 25

    How to get the value of "Label" inside the repeater?

  26. 26

    How can I change the output of a label, based on what's selected from a dropdown list (C# in ASP.NET)

  27. 27

    How can php change label html value?

  28. 28

    how can i add h3 code from asp.net behind code?

  29. 29

    Transfer value from code behind in xaml page to change expander foreground

HotTag

Archive