1

アプリケーションから別のユーザーのツイートをダウンロードしたいアプリケーションがあります:

DataTable dt = obj.GetTableSP("GetAllBioOrderByNewest");

foreach (DataRow dr in dt.Rows)
{
    WebClient wb = new WebClient();
    Uri myUri = new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&count=10&screen_name=" + dr["TwitterHandle"].ToString());
    wb.DownloadStringAsync(myUri);
    wb.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wblastID_DownloadStringCompleted);
}

そしてここで、グリッドビューで結果をバインドする方法:

public void wblastID_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs args)
{
    try
    {
        XElement xmlTweets = XElement.Parse(args.Result);
        GridView1.DataSource = (from tweet in xmlTweets.Descendants("status")
                                select new Tweet
                                {
                                    ID = tweet.Element("id").Value,
                                    Message = tweet.Element("text").Value,
                                    UserName = tweet.Element("user").Element("screen_name").Value,
                                    TwitTime = tweet.Element("created_at").Value
                                }).ToList();


        GridView1.DataBind();
        if (GridView1.Rows.Count < 10)
        {
            viewmore.Visible = false;
        }
    }
    catch
    {
        MessageBox.Show("Error downloading tweets");
    }
}

しかし、ここでの問題は、データテーブルから最後のユーザーのツイートしか取得できないことです。

私が欲しいのは、すべてのユーザーの結果を組み合わせdtて、グリッドビューに表示することです。

4

2 に答える 2

1

wblastID_DownloadStringCompletedループで呼び出しているため、グリッドをイベントにバインドしないでください。foreach そのため、各反復で新しい詳細にバインドされます。新しいコレクション (listまたはdatatable) を作成し、foreach ループの後で gridview を新しいコレクションにバインドする必要があります。

于 2013-03-28T11:51:39.680 に答える
0

wblastID_DownloadStringCompleted メソッドからすべての gridview 呼び出しを削除します。代わりに、データテーブルであるパブリック プロパティを用意してください。for each ステートメントは wblastID_DownloadStringCompleted メソッドを呼び出すため、データテーブルを追加するだけです。for ステートメントが終了したら、データ ソースをバインドします。いくつかの疑似コード:

someMethod
 for each twitterName as strin in myTable
     dim myFoundTweets as datatable
     dim myTweetName as string = "Your API Call To Get The name"

     myFoundTweets = addMe(myFoundTweets , myTweetName )

 next

  'now bind the source
end Metod


private sub addMe(byval myTweetName as string, byVal myTable as table)
   'parse the string here
   'add the values to a table or list of object
   'return it
end sub

より具体的な例が必要な場合は、お知らせください

于 2013-03-28T11:57:34.297 に答える