开发者

table will not show when populating from page_load

开发者 https://www.devze.com 2023-03-01 01:50 出处:网络
I am trying to populate a table in page_load, but nothing开发者_开发知识库 is showing and I know I have results from the database. here is my code:

I am trying to populate a table in page_load, but nothing开发者_开发知识库 is showing and I know I have results from the database. here is my code:

p

rotected void Page_Load(object sender, EventArgs e)
        {

            StreamReader reader = new StreamReader(Page.Request.InputStream);
            data = reader.ReadToEnd();
            reader.Close();


            string queryKeys = "";
            if (data != "")
            {
                string[] IDs = data.TrimEnd().Split(' ');
                SQLiteConnection sqlite_connectionUM = new SQLiteConnection("Data Source=" + path_to_um + ";Version=3;");

                sqlite_connectionUM.Open();
                   foreach (string ID in IDs)
                   {
                SQLiteCommand sqlite_queryMax = sqlite_connectionUM.CreateCommand();
                sqlite_queryMax.CommandText = "SELECT Keywords.Word from Keywords where Cluster = @c ORDER BY Keywords.Score LIMIT 5";
                sqlite_queryMax.Parameters.Add(new SQLiteParameter("@c", IDs[0]));
                SQLiteDataReader keywords = sqlite_queryMax.ExecuteReader();
                while (keywords.Read())
                {
                    queryKeys += keywords.GetString(0) + " ";
                }

                showRecommendations(queryKeys);
     }
                queryKeys = "";
            }

        }

And this is my showRecommendations method:

public void showRecommendations(string data)
        {

            Recommendations recommendList = new Recommendations();
            List<string> similarUsers = new List<string>();
            List<RecommendedWebsites> recommendationList = new List<RecommendedWebsites>();


            recommendationList = recommendList.getRecommendations(data);


             TableRow trow ; 
            TableCell tcell;
            recommendedsites.Visible = true;
             foreach (RecommendedWebsites recommendation in recommendationList)
            {
                Label1.Text = recommendation.getTitle();
                 trow = new TableRow (); 

                    tcell= new TableCell (); 
                    tcell.Controls.Add(new LiteralControl("<b>" + recommendation.getTitle() + "</b>")); 
                    trow.Cells.Add(tcell);
                    tcell.Controls.Add(new LiteralControl("<p> <a href=\"" + recommendation.getLink() + "\"</a>" + recommendation.getLink() + "</p>"));
                    trow.Cells.Add(tcell);
            recommendedsites.Rows.Add(trow); 
            }

        }

why isn't it showing? I had tried this with a normal click from a button, and the table appeared without any problem


Is recommendedsites a asp.net data control (gridview or something like that) if it is, you may want to add recommendedsites.DataBind();

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号