Click here to Skip to main content
15,908,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this problem, i search the DB and return results which i turn into links and print them but with the way i have chosen "Response.Write();" i get the results printed at the upper left corner, which sucks cause it messes up my whole page... :(

Is there a way i can print at a specific location (under the search bar preferably) and keep the results as links ?

Thanks in advance!





C#
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);
            }
        }
Posted

1 solution

Hi,

How about using a label, applying css class as per your requirement and just assigning its text from the code behind. This could be more easier.
 
Share this answer
 
Comments
frCake 29-Oct-14 8:21am    
yes but what if the search results population varies,i feel labels kinda static
[no name] 29-Oct-14 8:23am    
if the data could be large then why not use a control like grid or listview or repeater.. any one out of these many to bind. Will be easier. Isnt it ?
frCake 29-Oct-14 8:27am    
yes for sure ! i tried to use GridView , but i couldnt bind var finder, some code could help me bind it to a gridview! thanks
[no name] 29-Oct-14 8:28am    
Glad that it worked for you ! :)
frCake 29-Oct-14 8:31am    
no , what im saying is , i need some code to understand how i can bind var field to the gridview.!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900