0

JSONドキュメントを取得してリストに入れ、グリッドビューにバインドしようとしています。私はいくつかの異なる方法を試しましたが、何も機能しません。これが私のコードで、問題は最後の 4 行にあります。

   protected void Page_Load(object sender, EventArgs e)
    {


        var from = origin.Text;
        var to = destination.Text;
        var requesturl = @"http://maps.googleapis.com/maps/api/directions/json?origin =" + from + "&alternatives=false&units=imperial&destination=" + to + "&sensor=false;";
        string content = file_get_contents(requesturl); 


        JavaScriptSerializer jss = new JavaScriptSerializer();
        var d = jss.Deserialize<dynamic>(content);
        List<string> sl = d;

        GridView1.DataSource = content;
        GridView1.DataBind();



    }
4

1 に答える 1

0

これらのルートを一覧表示するには、次の 2 つの方法があります。

1 - GridView の使用:

<asp:GridView ID="grdExample" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField HeaderText="Directions">
            <ItemTemplate>
                <%# Container.DataItem %>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

GridView のバインド:

List<string> strings = new List<string>() { "Ha!", "Hey!", "Yo!" };

grdExample.DataSource = strings;
grdExample.DataBind();

2 - リピーターの使用 (よりシンプルで柔軟、独自の HTML が必要):

<asp:Repeater ID="rptExample" runat="server" >
    <ItemTemplate>
        <%# Container.DataItem %>
    </ItemTemplate>
</asp:Repeater>

バインド:

List<string> strings = new List<string>() { "Ha!", "Hey!", "Yo!" };

rptExample.DataSource = strings;
rptExample.DataBind();
于 2013-03-06T23:31:00.463 に答える