ajax投票不刷新



    无标题页
   
function clickit() {
        var dom=document.all;
        var el=event.srcElement;
        if(el.tagName=="INPUT"&&el.type.toLowerCase()=="radio")
        {
                for(i=0;i                {
                        if(dom[i].tagName=="INPUT"&&dom[i].type.toLowerCase()=="radio")
                        {
                                dom[i].checked=false;
                        }
                }
        }
        el.checked=true;
}



   
   


       
           
               
           
           
               
           
       

                   请选择一张进行投票

               

                   
                   

                   
                      
                         
                                  
                                    

                                                                       
                            

                         
 
                         

                            
                           
                             
                             
                             
                           

                              
                              
                              
                              
                              
                              
                              
                         

                      

                   
                   
               
       
   


 后台:

public partial class vote : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindList();
            BindGrid();
        }
    }

    public void BindList()
    {
        SqlConnection sqlCon = DB.CreateSqlCon();
        string sqlSel = "select photoTitle,photoPath from photoInfo";
        SqlCommand sqlCmd = new SqlCommand(sqlSel, sqlCon);
        SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        this.DataList1.DataSource = ds;
        this.DataList1.DataBind();
    }

    public void BindGrid()
    {
        SqlConnection sqlCon = DB.CreateSqlCon();
        string sqlSel = "select photoId,photoTitle,photoCount from photoInfo";
        SqlCommand sqlCmd = new SqlCommand(sqlSel, sqlCon);
        SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        this.DataGrid1.DataSource = ds;
        this.DataGrid1.DataBind();
    }

    protected void btnVote_Click(object sender, EventArgs e)
    {
        int photoCount;
        SqlConnection sqlCon=DB.CreateSqlCon();

        foreach(DataListItem   items   in   this.DataList1.Items)
        {   
            foreach(Control ctl in  items.Controls)
            {   
               RadioButton   r   =   ctl   as   RadioButton;
               if (r != null && r.Checked)
               {
                   //获得用户选择的项   
                   string strPhotoName= r.Text;
                   string sqlSel = "select photoCount from photoInfo where photoTitle='" + strPhotoName + "'";
                   SqlCommand sqlCmd = new SqlCommand(sqlSel, sqlCon);
                   SqlDataReader dr = sqlCmd.ExecuteReader();
                   if (dr.Read())
                   {
                       photoCount = dr.GetInt32(0);
                       dr.Close();
                       photoCount++;
                       string sqlUpdate = "update photoInfo set photoCount='" + photoCount + "' where photoTitle='" + strPhotoName + "'";
                       SqlCommand sqlUpdateCmd = new SqlCommand(sqlUpdate, sqlCon);
                       sqlUpdateCmd.ExecuteNonQuery();
                       sqlCon.Close();
                       BindGrid();

                       //this.DataGrid1.Visible = true;
                       //DB.Alert("投票成功");
                   }
                   else
                   {
                       dr.Close();
                   }                   
               }
               else
               {
                   //DB.Alert("请先选择一张图片");
               }
            }
        }        
    }    
}

 


请使用浏览器的分享功能分享到微信等