从page_load填充时,表格不会显示

时间:2011-04-28 09:25:30

标签: c# asp.net event-handling

我正在尝试在page_load中填充一个表,但没有显示任何内容,我知道我有来自数据库的结果。这是我的代码:

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 = "";
            }

        }

这是我的showRecommendations方法:

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); 
            }

        }

为什么不显示?我通过按钮的正常点击尝试了这个,并且表格没有任何问题

1 个答案:

答案 0 :(得分:0)

如果推荐使用asp.net数据控件(gridview或类似的东西),你可能想要添加recommendedsites.DataBind();