C#搜索结果,显示在特定位置

时间:2014-10-29 11:58:02

标签: c# sql printing hyperlink

我有这个问题,我搜索数据库并返回结果,我将其转换为链接并打印它们,但我选择了“Response.Write();”我得到的结果印在左上角,这很糟糕,因为它弄乱了我的整个页面...... :(

有没有办法可以在特定位置打印(最好在搜索栏下方)并将结果保存为链接?

提前致谢!

  protected void Button1_Click1(object sender, EventArgs e)
    {
        DataTable PassRecord = new DataTable();
        String str = "select First_Name,Email_Account,Surname,id from ID where (First_Name like '%'+ @search +'%' ) OR (Surname like '%'+ @search +'%') OR (Email_Account like '%'+ @search +'%')";
        SqlCommand Srch = new SqlCommand(str, con);
        Srch.Parameters.Add("@search", SqlDbType.NVarChar).Value = TextBox1.Text;
        if (TextBox1.Text != "")
        {
            con.Open();
            Srch.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = Srch;
            DataTable dt = new DataTable();
            DataTable dtResult = new DataTable();
            da.Fill(dt);
            PID = (int)(Session["id"]);                      
            int SaveTheFirst = PID;
            foreach (DataRow dr in dt.Rows)
            { 
                PID2 = dr["id"].ToString() ;
                if (PID.ToString() != PID2 )
                {
                    counter++;               
                    var field = "<a href='" + Page.ResolveUrl("~/PageView.aspx?Email=" + dr["id"].ToString()) + "'>" + (dr["First_Name"] + "").ToString() + "</a>";
                    Response.Write(field);
                    HttpContext context = HttpContext.Current;
                    Response.Write("<br/>");
                }
            }
            con.Close();
        }
        else
        {
            string display = " Not Valid Search Criteria!";
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);
        }
    }

0 个答案:

没有答案