关于google
下面的代码怎么让datalist绑定到的搜索结果不用listbox,并且在datalist有超连接,还有就是请问怎么得到总页数并进行分页。请高手指点一下,谢谢。private void Button1_Click(object sender, System.EventArgs e)
{

try
{
sKey="R1SnlcZQFHIBYlBCYdip3j1ERCvueU2Z";
localhost.GoogleSearchService s=new localhost.GoogleSearchService();
localhost.GoogleSearchResult r=s.doGoogleSearch(sKey, TextBox1.Text, 
0, 10, false, "", false, "", "", "");
localhost.ResultElement[] re=r.resultElements;
this.ListBox1.Items.Clear();
for (int i=0;i<re.Length;i++)
{ this.ListBox1.Items.Add((re[i].title));
this.ListBox1.Items.Add((re[i].URL));

}

         
}
catch(Exception eee)
{
}
private void ListBox1_DoubleClick(object sender, System.EventArgs e)
{
try
{
String url;
url=ListBox1.SelectedItem.Text ;
Process p  = Process.Start(@url);
}
catch (Exception ee)
{
}
}
}

解决方案 »

  1.   

    一般datalist、repeater的分页都使用PagedDataSource,当然你也可以用别的方法,还是给你一个例子吧:.aspx页面,下面这段代码放在<form></form>之间:
    <table width="100%" border="0">
    <tr>
    <td>
    <asp:label id="lblCurrentPage" runat="server"></asp:label></td>
    </tr>
    <tr>
    <td>
    <asp:button id="cmdPrev" runat="server" text=" <上一页"></asp:button>
    <asp:button id="cmdNext" runat="server" text="下一页> "></asp:button></td>
    </tr>
    </table>
    <table width="100%">
    <asp:DataList id="DataList1" runat="server">
    <ItemTemplate>
    <tr>
    <td>
    <asp:HyperLink id="HyperLink1" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "url") %>' runat="server">
    <%# DataBinder.Eval(Container.DataItem, "title") %>
    </asp:HyperLink></td>
    </tr>
    </ItemTemplate>
    </asp:DataList>
    </table>
    -----------------------------------------------------------
    .aspx.cs文件中:protected System.Web.UI.WebControls.Label lblCurrentPage;
    protected System.Web.UI.WebControls.Button cmdPrev;
    protected System.Web.UI.WebControls.Button cmdNext;
    protected System.Web.UI.WebControls.DataList DataList1;private void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    {
    BindList();
    }
    }void BindList() 
    {
    ICollection collectionSource = this.CreateDataSource();
    PagedDataSource objPds = new PagedDataSource();
    objPds.DataSource = collectionSource;
    objPds.AllowPaging = true;
    objPds.PageSize = 3; objPds.CurrentPageIndex = CurrentPage;  lblCurrentPage.Text = "页次: " + (CurrentPage + 1).ToString() + " of " 
    + objPds.PageCount.ToString(); cmdPrev.Enabled = !objPds.IsFirstPage;
    cmdNext.Enabled = !objPds.IsLastPage; DataList1.DataSource= objPds;
    DataList1.DataBind();
    }ICollection CreateDataSource() 
    {
    DataTable dt = new DataTable();
    DataRow dr; dt.Columns.Add(new DataColumn("title", typeof(string)));
    dt.Columns.Add(new DataColumn("url", typeof(string))); for (int i = 0; i < 9; i++) 
    {
    dr = dt.NewRow(); dr[0] = "this is title " + i;
    dr[1] = "http://www." + i.ToString() + ".com"; dt.Rows.Add(dr);
    } DataView dv = new DataView(dt);
    return dv;
    }public int CurrentPage
    {
    get
    {
    object o = this.ViewState["_CurrentPage"];
    if (o == null)
    return 0;
    else
    return (int) o;
    } set
    {
    this.ViewState["_CurrentPage"] = value;
    }
    }private void cmdPrev_Click(object sender, System.EventArgs e)
    {
    CurrentPage -= 1;
    BindList();
    }private void cmdNext_Click(object sender, System.EventArgs e)
    {
    CurrentPage += 1;
    BindList();
    }#region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }/// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.cmdPrev.Click += new System.EventHandler(this.cmdPrev_Click);
    this.cmdNext.Click += new System.EventHandler(this.cmdNext_Click);
    this.Load += new System.EventHandler(this.Page_Load);}
    #endregion