using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DAL;
using BLL;
using Model;
namespace YzQSS
{
public partial class StatPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rptQuestion.DataSource = pds();
rptQuestion.DataBind();
}
}
protected bool SingleOrMulit(object obj,string type)
{
if (obj.ToString() == type)
{
return true;
}
else
{
return false;
}
}
private PagedDataSource pds()
{
Label2.Text = Application["d3"].ToString();
Label1.Text = Application["d2"].ToString();
string app = Application["d1"].ToString();
List<Question> list = new List<Question>();
DataSet ds = new DataSet();
ds = (BLL_question.GetList("q_prjID='" + app + "'"));
if (ds != null && ds.Tables.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string myvalue = ds.Tables[0].Rows[i][0].ToString();
Question q = new Question();
q.Qutid = Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString());
q.Qutname = ds.Tables[0].Rows[i][1].ToString();
q.Quttype = ds.Tables[0].Rows[i][3].ToString();
DataSet dss = new DataSet();
dss = (BLL_answer.GetList("a_qutID='" + q.Qutid + "'"));
if (dss != null && dss.Tables.Count > 0)
{
List<answer> a = new List<answer>();
for (int j = 0; j < dss.Tables[0].Rows.Count; j++)
{
a.Add(new answer() { Aswname = dss.Tables[0].Rows[j][1].ToString() });
}
q.Answers = a;
}
list.Add(q);
}
}
PagedDataSource pds = new PagedDataSource();
pds.DataSource =list;
pds.AllowPaging = true;//允许分页
pds.PageSize = 2;//单页显示项数
pds.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
return pds;
//this.Repeater1.DataSource = list;
//this.Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
HyperLink lpfirst = (HyperLink)e.Item.FindControl("hlfir");
HyperLink lpprev = (HyperLink)e.Item.FindControl("hlp");
HyperLink lpnext = (HyperLink)e.Item.FindControl("hln");
HyperLink lplast = (HyperLink)e.Item.FindControl("hlla");
int n = Convert.ToInt32(pds().PageCount);//n为分页数
int i = Convert.ToInt32(pds().CurrentPageIndex);//i为当前页
Label lblpc = (Label)e.Item.FindControl("lblpc");
lblpc.Text = n.ToString();
Label lblp = (Label)e.Item.FindControl("lblp");
lblp.Text = Convert.ToString(pds().CurrentPageIndex + 1);
if (i <= 0)
{
lpfirst.Enabled = false;
lpprev.Enabled = false;
lplast.Enabled = true;
lpnext.Enabled = true;
}
else
{
lpprev.NavigateUrl = "?page=" + (i - 1);
}
if (i >= n - 1)
{
lpfirst.Enabled = true;
lplast.Enabled = false;
lpnext.Enabled = false;
lpprev.Enabled = true;
}
else
{
lpnext.NavigateUrl = "?page=" + (i + 1);
}
lpfirst.NavigateUrl = "?page=0";//向本页传递参数page
lplast.NavigateUrl = "?page=" + (n - 1);
}
}
protected void btnReturn_Click(object sender, EventArgs e)
{
Page.Response.Redirect("chooseProject.aspx");
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string cb = "";//复选框
string rb = "";//单选框
string tb = "";//如果有文本框
foreach (RepeaterItem item in rptQuestion.Items)
{
CheckBoxList cb1 = (CheckBoxList)item.FindControl("cb");
RadioButtonList rb1 = (RadioButtonList)item.FindControl("rb");
TextBox tb1 = (TextBox)item.FindControl("tb");
//CheckBox cb = (CheckBox)item.FindControl("CheckBoxRole");
if (cb1.Visible == true)
{
for (int i = 0; i < cb1.Items.Count; i++)
{
if (cb1.Items[i].Selected == true)
{
cb += "'" + cb1.Items[i].Value + "'" + ",";
}
}
}
if (rb1.Visible == true)
{
for (int i = 0; i < rb1.Items.Count; i++)
{
if (rb1.Items[i].Selected == true)
{
rb = "'" + rb1.Items[i].Value + "'";
}
}
}
if (tb1.Visible == true)
{
tb = tb1.Text + "|";
}
//RadioButtonList RadioButtonList1 = item.FindControl("RadioButtonList1") as RadioButtonList;
//foreach (ListItem l in RadioButtonList1.Items)
//{
// if (l.Selected == true)
// {
// Response.Write(l.Text + "<br>" + l.Value);
// }
//}
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StatPage.aspx.cs" Inherits="YzQSS.StatPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>问卷调查</title>
<script type="text/javascript">
function openwin(name) {
window.open(name, '', 'width=500,height=400,scrollbars=no');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div><table>
<tr>
<td >
<asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label><br />
问卷截止日期:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
<br />
<table>
<asp:Repeater ID="rptQuestion" runat="server" OnItemDataBound="Repeater1_ItemDataBound" >
<ItemTemplate>
<tr>
<td><%#Eval("qutName") %></td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="rb" runat="server" DataSource='<%#Eval("Answers") %>' DataTextField="Aswname" Visible=' <%# SingleOrMulit(Eval("Quttype"),"单选")%>' >
</asp:RadioButtonList>
<asp:CheckBoxList ID="cb" runat="server" DataSource='<%#Eval("Answers") %>' DataTextField="Aswname" Visible=' <%# SingleOrMulit(Eval("Quttype"),"多选")%>'>
</asp:CheckBoxList>
<asp:TextBox ID="tb" runat="server" TextMode="MultiLine" Width="200"
Height="80px" Visible=' <%# SingleOrMulit(Eval("Quttype"),"文本")%>'></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan="2">
<hr style="border-top:1pt;"/>
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
<tr>
<td colspan="2" style="font-size:12pt;">
共<asp:Label ID="lblpc" runat="server" Text="Label"></asp:Label>页 当前为第
<asp:Label ID="lblp" runat="server" Text="Label"></asp:Label>页
<asp:HyperLink ID="hlfir" runat="server" Text="首页"></asp:HyperLink>
<asp:HyperLink ID="hlp" runat="server" Text="上一页"></asp:HyperLink>
<asp:HyperLink ID="hln" runat="server" Text="下一页"></asp:HyperLink>
<asp:HyperLink ID="hlla" runat="server" Text="尾页"></asp:HyperLink>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</table>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="提交" οnclick="btnSubmit_Click" />
<asp:Button ID="btnReturn" runat="server" Text="返回" οnclick="btnReturn_Click" />
</div>
</form>
</body>
</html>