日期:2014-05-18 浏览次数:20501 次
private void ShowTableList(string tableName, bool clearTable)
{
if (clearTable == true)
{
this.ShowTable.Rows.Clear();
}
SqlConnection conn = new SqlConnection(SqlConn.Connstring);
SqlCommand command = null;
if (tableName == "mainforum")
{
command = new SqlCommand("SELECT * FROM " + tableName + "WHERE id = " + Session["mainid"].ToString(), conn);
}
else
{
command = new SqlCommand("SELECT * FROM " + tableName + "WHERE titleid = " + Session["mainid"].ToString(), conn);
}
SqlDataReader datareader = null;
int num = GetRecordNumber(tableName);
Label[] label = new Label[num];
HyperLink[] hyperLink = new HyperLink[num];
TextBox[] textbox = new TextBox[num];
conn.Open();
datareader = command.ExecuteReader();//???????????????
int i = 0;
while (datareader.Read())
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
label[i] = new Label();
if (tableName == "mainforum")
{
label[i].Text = "Post author : " + datareader["author"].ToString() +
"<br>Post title : " + datareader["title"].ToString() +
"<br>Last modify time : " + datareader["releasetime"].ToString() + "  ";
}
else
{
label[i].Text = "Post author : " + datareader["author"].ToString() +
"<br>Last modify time : " + datareader["lastmodifytime"].ToString() + "  ";
}
cell.Controls.Add(label[i]);
hyperLink[i] = new HyperLink();
hyperLink[i].Text = "[Modified post]";
hyperLink[i].Target = "_top";
if (tableName == "mainforum")
{
hyperLink[i].NavigateUrl = "ArticleModify.aspx?state=modifyMain";
}
else
{
hyperLink[i].NavigateUrl = "ArticleModify.aspx?state=modifySub&subid=" + datareader["id"].ToString();
}
cell.Controls.Add(hyperLink[i]);
row.Cells.Add(cell);
this.ShowTable.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
textbox[i] = new TextBox();
textbox[i].TextMode = TextBoxMode.MultiLine;
textbox[i].ReadOnly = true;
textbox[i].Width = 700;
textbox[i].Height = 100;
textbox[i].Text = "" + datareader["content"].ToString();
cell.Controls.Add(textbox[i]);
row.Cells.Add(cell);
this.ShowTable.Rows.Add(row);
}
datareader.Close();
conn.Close();
}