winform repeater 自定义多样式显示数据

杰2014 2016-04-01 11:07:30
我现在在做一个页面,就是可以把数据库里面的试题(有选择题、填空题、简答题和综合题)显示在一个页面上,用了repeater,看了网上人家做的,自己也学着做了一个显示的,但是做出来跟理想中的不一样,请大虾帮忙看下,是不是哪里写错了。
  <asp:Repeater ID="Repeater1" runat="server">            
<ItemTemplate>
<% int _type = (int)(ds.Tables[0].Rows[_nIndex++]["type"]);
if (_type == 1)
{%>
<div >
<div><%# "<b>第</b> "%><%=count++ %><%# "<b>题</b> " %></div>
<div><%# DataBinder.Eval(Container.DataItem, "text").ToString().Split('@')[0] %> </div>
<div style="background-color: #E6E6FA">
<%# "<b>参考答案:</b> " + DataBinder.Eval(Container.DataItem, "answer").ToString().Replace('@',' ') %>
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return confirm( '是否移除收藏? ');" CommandArgument='<%#Eval("qust_id") %>'> 删除</asp:LinkButton>
</div>
<br />

<%}
else if (_type == 2)
{%>

<div >
<div><%# "<b>第</b> "%><%=count++ %><%# "<b>题</b> " %></div>
<div><%# DataBinder.Eval(Container.DataItem, "text").ToString().Split('@')[0] %> </div>
<div><%# "A、" + DataBinder.Eval(Container.DataItem, "text").ToString().Split('@')[1] %></div>
<div><%# "B、" + DataBinder.Eval(Container.DataItem, "text").ToString().Split('@')[2] %></div>
<div><%# "C、" + DataBinder.Eval(Container.DataItem, "text").ToString().Split('@')[3] %></div>
<div><%# "D、" + DataBinder.Eval(Container.DataItem, "text").ToString().Split('@')[4] %></div>
<div style="background-color: #E6E6FA">
<%# "<b>参考答案:</b> " + DataBinder.Eval(Container.DataItem, "answer") %>
<asp:LinkButton ID="btnDel" runat="server" OnClientClick="return confirm( '是否移除收藏? ');" CommandArgument='<%#Eval("qust_id") %>'> 删除</asp:LinkButton>
</div>
<br />
</div>

<%}
%>
</ItemTemplate>

<FooterTemplate>
<div id="lstFoot">全部记录都已显示.</div>
</FooterTemplate>
</asp:Repeater>


我是根据题目的类型来展示的,所以我加了一个_type变量来判断,可是运行的结果是:
只要查询所有的试题便会出错,好像没有进入我的那个条件判断,直接把所有的样式走一遍似的
只查询一个题型便成这样子了
哪位大侠帮帮忙,做了好几天了,一筹莫展。
...全文
114 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
全栈极简 2016-04-01
  • 打赏
  • 举报
回复
你这是索引越界了,看看DataBinder.Eval绑定的text的值是什么。
杰2014 2016-04-01
  • 打赏
  • 举报
回复
引用 1 楼 guwei4037 的回复:
你这是索引越界了,看看DataBinder.Eval绑定的text的值是什么。
我知道越界了,因为选择题我是用 题目@A@B@C@D这样的方式存储的,所以我取值的时候就得用 <div><%# "A、" + DataBinder.Eval(Container.DataItem, "text").ToString().Split('@')[1] %></div>这个方法来取得题目跟四个选项,现在的问题是填空题也按着选择题的方式来显示,这当然有问题了,你看下我的显示语句那边 为什么我的<% int _type = (int)(ds.Tables[0].Rows[_nIndex++]["type"]); if (_type == 1) {%> 选择题显示样式 <%} else if (_type == 2) {%> 填空题显示样式 <%} %> 我现在的问题就是,为什么不能根据我的条件来显示

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧