第1个回答 2012-06-12
protected void Gridview1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Result")
{
Panel p = (Panel)e.Item.FindControl("Panel1");
if (Session["P"] == null)
{
p.Visible = true;
Session["P"] = 1;
}
else
{
p.Visible = false;
Session["P"] = null;
}
}
if (e.CommandName == "Voting")
{
CheckBoxList chk = (CheckBoxList)e.Item.FindControl("CheckBoxList1");
Label lbl = (Label)e.Item.FindControl("Label_Topic");
int TotalCount = 0,Count=0;
if (chk.SelectedIndex == -1)
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdateSucceed", "alert('尊敬的用户,请至少选择一项!')", true);
return;
}
else
{
DataSet ds_Topic = CoSt.Read("select * from OnlineSurvey where Topic='"+lbl.Text+"'");
if (ds_Topic.Tables.Count > 0 && ds_Topic.Tables[0].Rows.Count > 0)
{
TotalCount = Convert.ToInt32(ds_Topic.Tables[0].Rows[0]["TotalCount"].ToString());
}
TotalCount = TotalCount + 1;
int flag= CoSt.UpdateTotalCount(lbl.Text, TotalCount);
for (int i = 0; i < chk.Items.Count; i++)
{
if (chk.Items[i].Selected)
{
DataSet ds_Item = CoSt.Read("select * from Items where ItemID='"+chk.Items[i].Value+"'");
if (ds_Item.Tables.Count > 0 && ds_Item.Tables[0].Rows.Count > 0)
{
Count =Convert.ToInt32( ds_Item.Tables[0].Rows[0]["Count"].ToString());
}
Count = Count + 1;
CoSt.UpdateItemCount(Convert.ToInt32( chk.Items[i].Value), Count);
}
}
if (flag > 0)
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdateSucceed", "alert('投票成功,谢谢您的参与!')", true);
DataB();
}
else
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdateSucceed", "alert('投票失败,请重新后再试!')", true);
}
}
}
}