我HTML表我隱藏其將結合在頁面加載數據。按鈕綁定HTML表再次單擊
現在我有一個按鈕,將數據插入數據庫。我的問題是當我插入按鈕點擊數據時,我的頁面得到回傳。我的HTML表格數據將只顯示舊數據不是我已經添加的新數據。因爲html表格首先在pageload中綁定並且在單詞之後,我的控件將轉到button_click事件。
我試圖把對的IsPostBack的Page_Load但隨後第一次,當頁面加載得到HTML表計量不顯示任何數據。
我怎樣才能解決這個問題。
protected void Page_Load(object sender, EventArgs e)
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * from Ticket";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
// //Building an HTML string.
StringBuilder html = new StringBuilder();
//Table start.
html.Append("<table id='tbldata' style='table-layout:fixed;' border='0'>");
html.Append("<THEAD>");
html.Append("<TR>");
html.Append("<TH>Ticket</TH>");
html.Append("<TH>Priority</TH>");
html.Append("<TH>Status<div class='fildownarrow'></div></TH>");
html.Append("<TH>Practice Name<div class='fildownarrow'></div></TH>");
html.Append("<TH>Patient Name</TH>");
html.Append("<TH>Assigned</TH>");
html.Append("<TH>Subject</TH>");
html.Append("<TH style='width:100px;><a href='#'><div class='filtericon'></div></a></TH>");
html.Append("</TR>");
html.Append("</THEAD>");
if (dr.HasRows)
{
while (dr.Read())
{
html.Append("<tbody>");
html.Append("<tr>");
html.Append("<td>" + dr["Ticket_no"] + "</td>");
html.Append("<td>" + dr["Priority"] + "</td>");
html.Append("<td>" + dr["Status"] + "</td>");
html.Append("<td>" + dr["Practice_Name"] + "</td>");
html.Append("<td>" + dr["Patient_Name"] + "</td>");
html.Append("<td>" + dr["Assign_User_Name"] + "</td>");
html.Append("<td>" + dr["Msg_Subject"] + "</td>");
html.Append("</tr>");
html.Append("</tbody>");
}
}
//Table end.
html.Append("</table>");
//Append the HTML string to Placeholder.
PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });
dr.Close();
dr.Dispose();
}
不要做這種方式,檢索數據到一個列表並將其綁定到ListView控件。將爲您節省大量的麻煩。 – Banana
使用SqlDataAdapter來檢索數據,並使用Repeater,DataList或GridView來顯示數據 – Sandeep