问题:1,无法循环绑定投票的标题和选项
解决方法: 在Repeater绑定中添加ItemDataBound事件,选项用RadioButtonList绑定,附源代码:
Default页,源页面
复制代码 代码如下:
<div>
广大网友对保障房建设相关问题调查<br />
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td colspan="3">
<b>
<%# Eval("t_timu")%>
<asp:Literal ID="Literal1" Text='<%# Eval("t_id")%>' runat="server"></asp:Literal>

</b>
</td>
</tr>
<tr>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
</asp:RadioButtonList>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" />&nbsp;
<asp:Button ID="Button2" runat="server" Text="查看结果" OnClick="Button2_Click" />
</div>


对应的cs页:
复制代码 代码如下:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Literal Literal1 = (Literal)e.Item.FindControl("Literal1");
RadioButtonList RadioButtonList1 = (RadioButtonList)e.Item.FindControl("RadioButtonList1");
RadioButtonList1.DataSource = dcw_toupiao_M.dcw_toupiao_getxuanxian(Convert.ToInt32(Literal1.Text));
RadioButtonList1.DataTextField = "x_name";
RadioButtonList1.DataValueField = "x_id";
RadioButtonList1.DataBind();
}

问题2: 无法循环获得用户的选择
解决方法: 先循环Repeater控件的Item获得RadioButtonList控件,循环检测是否为选中状态,,如果是则拼接到一个字符串中,
再把题目的编号获得拼接起来,循环添加,附源代码:

Default的cs页:
复制代码 代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string zifu = "";
string Pid = "";
int tiaoshu = 5;
foreach (RepeaterItem iemt in Repeater1.Items)
{
RadioButtonList rbtn = iemt.FindControl("RadioButtonList1") as RadioButtonList;
try
{
if (rbtn.SelectedItem.Selected)
{
zifu += rbtn.SelectedItem.Value + ",";
}
Literal Literal1 = (Literal)iemt.FindControl("Literal1"); //e.Item.FindControl("");
if (Literal1.Text != "")
{
Pid += Literal1.Text + ",";
}
}
catch (Exception ex)
{
}
}
string[] xid = null;
xid = zifu.TrimEnd(',').Split(',');
string[] pid = null;
pid = Pid.TrimEnd(',').Split(',');
if (dcw_toupiao_M.dcw_toupiao_Insert(xid, pid, tiaoshu))
{
this.ClientScript.RegisterClientScriptBlock(typeof(string), "ok", "<script>alert('投票成功!谢谢参与')</script>");
}
else
{
this.ClientScript.RegisterClientScriptBlock(typeof(string), "ok", "<script>alert('请完成选择')</script>");
}
}

DAL页:
复制代码 代码如下:
public static bool dcw_toupiao_Insert(string[] xid, string[] pid, int tiaoshu)
{
bool flag = false;
for (int i = 0; i < pid.Length; i++)
{
SqlParameter[] prm = new SqlParameter[2];
prm[0] = new SqlParameter("@xid", Int32.Parse(xid[i]));
prm[1] = new SqlParameter("@pid", Int32.Parse(pid[i]));
if (dcw_toupiao_M.dcw_toupiao_gettcount(Convert.ToInt32(xid[i]), Convert.ToInt32(pid[i])))
{
flag = _dc_toupiao_DB.SqlHelper.ExeucteNonQuery("sm_dcw_toupiao_Insert", CommandType.StoredProcedure, prm) > 0;
}
}

return flag;
}

所掌握的技巧:
JavaScript跳转:
this.ClientScript.RegisterClientScriptBlock(typeof(string), "ok", "<script>alert('投票成功!谢谢参与')</script>");
两种获得控件的方法:
Literal Literal1 = (Literal)e.Item.FindControl("Literal1");
Literal Literal1 = e.Item.FindControl("Literal1") as Literal;
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。