当前位置: 代码迷 >> ASP.NET >> 为什么数据库内容显示了两次?该怎么处理
  详细解决方案

为什么数据库内容显示了两次?该怎么处理

热度:9233   发布时间:2013-02-26 00:00:00.0
为什么数据库内容显示了两次?
我采用了 <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);

                        }

                }


------解决方案--------------------------------------------------------
跟踪一下
------解决方案--------------------------------------------------------
好像控件初次load时也会有selectchange事件
------解决方案--------------------------------------------------------
跟踪调试一下
------解决方案--------------------------------------------------------
检查一下你的代码,是不是有逻辑问题。如果没有的话,那你就跟踪调试一下最方便了。
------解决方案--------------------------------------------------------
你在pageload中有没有绑定
有要加上if(!ispostback)
{
//your code here
}
------解决方案--------------------------------------------------------
  相关解决方案