<div style="margin-top: 20px; width: 270px; white-space: normal">
                                            <asp:Repeater ID="dlContet" runat="server" OnItemDataBound="dlContet_ItemDataBound">
                                                <ItemTemplate>
                                                    <div>
                                                        <asp:Label Text='<%# Eval("F_Question") %>' runat="server" ID='lbl'></asp:Label>
                                                        <asp:HiddenField ID="hidID" runat="server" Value='<%# Eval("ID") %>' />
                                                    </div>
                                                    <asp:RadioButtonList ID="rbtnQuestion" runat="server" RepeatDirection="Horizontal">
                                                    </asp:RadioButtonList>
                                                </ItemTemplate>
                                            </asp:Repeater>
</div>

protected void dlContet_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
        {
            string strID = ((DataRowView)e.Item.DataItem)["ID"].ToString();
            Repeater rpContet = e.Item.FindControl("rpContet") as Repeater;
            RadioButtonList rbtnQuestion = e.Item.FindControl("rbtnQuestion") as RadioButtonList;
            string strSqlPic = "select  ID,F_Content,F_QuestionID,F_IsKey from  T_QAnswer where F_QuestionID='" + strID + "'";

            DataSet dsPic = objData.ExcSqlDataSet(strSqlPic);
            if (dsPic != null && dsPic.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsPic.Tables[0].Rows.Count; i++)
                {
                    rbtnQuestion.Items.Add(new ListItem(dsPic.Tables[0].Rows[i]["F_Content"].ToString(), dsPic.Tables[0].Rows[i]["ID"].ToString()));
                }
            }
            //else { rbtnQuestion.Items.Add(new ListItem("", "")); }

        }
    }

 

 

 

 

 protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        string strSessionID = Session.SessionID;
        int j = 0, jCount = 0;
        string strName = txtName.Text;
        string strTel = txtTel.Text;
        string strIP = Xmhouse.Common.WebCommon.GetRealIP();
        Regex regTel = new Regex(@"^1[3-8]\d{9}$|^\d{3}-\d{8}$|^\d{4}-\d{7}$");

 

        string strTel_ = strTel.Trim();
        if (string.IsNullOrEmpty(strTel_) || (!Regex.IsMatch(strTel_, @"^\d{3,4}\d{7,8}$") && !Regex.IsMatch(strTel_, @"^[0]{0,1}(13|14|15|18)\d{9}$")))
        {
            Response.Write(jsAlert(403, "友情提醒:请输入正确的手机号码(11位)!", 2, "IndexNew.aspx"));
            Response.End();
        }
        string strSqlTel = "select * from T_QAactiveInfo where  DATEDIFF(DAY, GETDATE(), F_DBTime)=0 and F_Tel='" + strTel + "'";
        DataSet dsCount = objData.ExcSqlDataSet(strSqlTel);
        if (dsCount.Tables[0].Rows.Count >= 3)
        {
            Response.Write(jsAlert(403, "友情提醒:您这个手机号码已经参加了此次活动,请不要重复提交!", 2, "IndexNew.aspx"));
            Response.End();
        }


        string strIpName = "dbo.f_GetIPName('" + strIP + "')";

        //string strSql = "SELECT  top 1   DATEDIFF(MINUTE, GETDATE(), F_EndTime) from T_QAQuestion where F_StartOrEnd=1";
        //int iNum = objData.ExcSqlIntScalar(strSql);
        //if (iNum < 0)
        //{
        //    ClientScript.RegisterStartupScript(this.GetType(), "js", "alert('本次活动已结束')", true);
        //    btnSave.Enabled = false;
        //    btnSave.Text = "本次活动已结束";
        //}
        //else
        //{
        //    btnSave.Enabled = true;
        //    btnSave.Text = "提交";
        //}

        for (int i = 0; i < dlContet.Items.Count; i++)//3
        {
            Repeater rpContet = (Repeater)dlContet.Items[i].FindControl("rpContet");
            HiddenField hidID = (HiddenField)dlContet.Items[i].FindControl("hidID");
            string strQuestionID = hidID.Value;
            RadioButtonList rbtnQuestion = (RadioButtonList)dlContet.Items[i].FindControl("rbtnQuestion");
            string strAnswerID = rbtnQuestion.SelectedValue;
            if (!string.IsNullOrEmpty(strAnswerID))
            {
                //外网
                string strInsertSql = "Insert into [T_QAactiveInfo]([F_Name] ,[F_Tel] ,[F_IP],[F_DBTime] ,[F_QuestionID],[F_AnswerID],[F_IPName],F_SessionID) values('{0}','{1}','{2}',getdate(),'{3}','{4}',{5},'{6}')";
                // string strInsertSql = "Insert into [T_QAactiveInfo]([F_Name] ,[F_Tel] ,[F_IP],[F_DBTime] ,[F_QuestionID],[F_AnswerID]) values('{0}','{1}','{2}',getdate(),'{3}','{4}')";
                strInsertSql = string.Format(strInsertSql, strName, strTel, strIP, strQuestionID, strAnswerID, strIpName, strSessionID);
                // strInsertSql = string.Format(strInsertSql, strName, strTel, strIP, strQuestionID, strAnswerID);
                int iRows = objData.ExcSqlNonQuery(strInsertSql);
                if (iRows > 0)
                    j++;
            }
            jCount++;
        }
        if (j == jCount)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "js", "alert('提交成功!')", true);
            txtName.Text = "";
            txtTel.Text = "";
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "js", "alert('回答要全部填写哦')", true);
        }
    }

 

 

posted on 2011-08-22 11:49  .NET每天一小步  阅读(286)  评论(1)    收藏  举报