我采用了<select>onchange()事件,触发动态创建table,在创建table的时候为什么从数据库读取了两遍数据呢
代码如下:
protected void articleType_SelectedIndexChanged(object sender, System.EventArgs e)
{
SqlConnection conn1 = new SqlConnection(ConfigurationSettings.AppSettings["connstring"]);
conn1.Open();
string articleTypeId = this.articleType.SelectedValue;
SqlCommand articleCmd1 = new SqlCommand("select * from Article where Type="+articleTypeId,conn1);
SqlDataReader articleSdr1 = articleCmd1.ExecuteReader();
while(articleSdr1.Read())
{
TableRow r = new TableRow();
TableCell c1 = new TableCell();
c1.Controls.Add(new LiteralControl(articleSdr1[1].ToString()));
r.Cells.Add(c1);
TableCell c2 = new TableCell();
c2.Controls.Add(new LiteralControl("<input type='radio' value='"+articleSdr1[0].ToString()+"'> "));
r.Cells.Add(c2);
articleTable.Rows.Add(r);
}
}
[此贴子已经被作者于2007-1-10 14:16:57编辑过]