How to Use Bing API c#
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
BingService service = new BingService();
//foreach (ImageResult result in response.Image.Results)
//{
if (!RadioButton1.Checked)
{
if (RadioButtonList1.SelectedItem != null)
{
if (RadioButtonList1.SelectedItem.Value == "Videos")
{
SearchRequest request2 = new SearchRequest();
request2.AppId = "83DFCBA3482E132EF9837E3B505DFD015773E909";
request2.Query = TextBox1.Text;
request2.Sources = new SourceType[]
{
SourceType.Video
};
SearchResponse response2 = service.Search(request2);
}
else
{
SearchRequest request = new SearchRequest();
request.AppId = "83DFCBA3482E132EF9837E3B505DFD015773E909";
request.Query = TextBox1.Text;
// SEARCH ONLY IMAGES (request)
request.Sources = new SourceType[]
{
SourceType.Image
};
SearchResponse response = service.Search(request);
DataList2.Visible = false;
dl.Visible = true;
var results = response.Image.Results;
dl.DataSource = results;
dl.DataBind();
}
}
else
{
SearchRequest request1 = new SearchRequest();
request1.AppId = "83DFCBA3482E132EF9837E3B505DFD015773E909";
request1.Query = TextBox1.Text;
// SEARCH ONLY WEB (request1)
request1.Sources = new SourceType[]
{
SourceType.Web
};
SearchResponse response1 = service.Search(request1);
dl.Visible = false;
DataList2.Visible = true;
var results = response1.Web.Results;
DataList2.DataSource = results;
DataList2.DataBind();
}
}
else
{
if (RadioButtonList1.SelectedItem.Value == "Videos")
{
}
else if (RadioButtonList1.SelectedItem.Value == "Images")
{
}
else
{
}
}
//}
}
protected void dl_ItemDataBound(object sender, DataListItemEventArgs e)
{
System.Web.UI.WebControls.Image img1 = (System.Web.UI.WebControls.Image)e.Item.FindControl("img");
img1.ImageUrl = ((MyBingServiceNetwork.ImageResult)(e.Item.DataItem)).MediaUrl;
}
protected void datalistto_itemdatabound(object sender, DataListItemEventArgs e)
{
HyperLink hyp = (HyperLink)e.Item.FindControl("hyp");
hyp.Text = ((MyBingServiceNetwork.WebResult)(e.Item.DataItem)).Title;
hyp.NavigateUrl = ((MyBingServiceNetwork.WebResult)(e.Item.DataItem)).Url.ToString();
Label lbl = (Label)e.Item.FindControl("lbl");
lbl.Text = ((MyBingServiceNetwork.WebResult)(e.Item.DataItem)).Description;
//LinkButton lnk = (LinkButton)e.Item.FindControl("lnk");
//lnk.Text = ((MyBingServiceNetwork.WebResult)(e.Item.DataItem)).Url.ToString();
//lnk.PostBackUrl = ((MyBingServiceNetwork.WebResult)(e.Item.DataItem)).Url.ToString();
Label lblurl = (Label)e.Item.FindControl("lblurl");
lblurl.Text = ((MyBingServiceNetwork.WebResult)(e.Item.DataItem)).DisplayUrl.ToString();
}
Comments
Post a Comment