首页 新闻 会员 周边 捐助

repeater绑定数据时不允许eval和if一起使用咋么破。。

0
悬赏园豆:20 [待解决问题]

我在绑定repeater的数据时遇到了if语句不支持的情况,我这里要实现的是根据数据中的格式字段来决定之后是使用何种控件,比如单选我就要用radiobutton,如果是多选就用checkbox,但是现在在做if判断的时候,报eval()只能在绑定时使用这个错误。

<asp:Repeater ID="rquestion" runat="server" OnItemDataBound="rquestion_ItemDataBound">
                <ItemTemplate>
                    <%if (Convert.ToInt32(Eval("questiontypeid")) == 1)
                      {%>

                    <div style="visibility: visible;" tabindex="-1" class="div_question div_question_mouseout">
                        <div class="div_preview">
                            <div class="div_title_question_all">
                                <div class="div_topic_question">1.</div>
                                <div class="div_title_question"><span><%# Eval("questionname") %></span></div>
                                <div style="clear: both;"></div>
                            </div>
                            <div class="div_table_radio_question">
                                <div class="div_table_clear_top"></div>
                                <ul>
                                    <asp:Repeater ID="rquestionItems" runat="server">
                                        <ItemTemplate>
                                            <li style="width: 99%;">
                                                <input type="radio"><%# Eval("itemname") %></li>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                    <div style="clear: both;"></div>
                                </ul>
                                <div class="div_table_clear_bottom"></div>
                            </div>
                            <div class="div_ins_question"></div>
                            <div class="spanLeft" style="height: 18px;">
                                <div style="clear: none; display: none;" class="div_ins_question spanLeft">*此题设置了跳转逻辑</div>
                                <div style="clear: none; display: none;" class="div_ins_question spanLeft"></div>
                            </div>
                            <div style="clear: none; display: none;" class="div_ins_question spanLeft"><a href="javascript:void(0);" onclick="insertQ(curover);" class="a555" style="text-decoration: underline;">在此题后插入新题</a></div>
                            <div style="clear: none;" class="spanRight">
                                <ul class="stuff">
                                    <li><a href="javascript:void(0);" onclick="editQ(this);" title="您也可以双击题目来进行编辑"><span class="design-icon design-edit"></span><span>编辑</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.copyQ();" title="复制此题"><span class="design-icon design-copy"></span><span>复制</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.deleteQ();" title="删除此题"><span class="design-icon design-delete"></span><span>删除</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveUp();" title="将此题上移"><span class="design-icon design-up"></span><span>上移</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveDown();" title="将此题下移"><span class="design-icon design-down"></span><span>下移</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveFirst();" title="将此题移动到第一题"><span class="design-icon design-first"></span><span>最前</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveLast();" title="将此题移动到最后一题"><span class="design-icon design-last"></span><span>最后</span></a></li>
                                    <div style="clear: both;"></div>
                                </ul>
                            </div>
                            <div style="clear: both;"></div>
                        </div>
                    </div>
                    <%}
                      else if (Convert.ToInt32(Eval("questiontypeid")) == 2)
                      {%>

                    <div style="visibility: visible;" tabindex="-1" class="div_question div_question_mouseout">
                        <div class="div_preview">
                            <div class="div_title_question_all">
                                <div class="div_topic_question">1.</div>
                                <div class="div_title_question"><span><%# Eval("questionname") %></span></div>
                                <div style="clear: both;"></div>
                            </div>
                            
                            <div class="div_ins_question"></div>
                            <div class="spanLeft" style="height: 18px;">
                                <div style="clear: none; display: none;" class="div_ins_question spanLeft">*此题设置了跳转逻辑</div>
                                <div style="clear: none; display: none;" class="div_ins_question spanLeft"></div>
                            </div>
                            <div style="clear: none; display: none;" class="div_ins_question spanLeft"><a href="javascript:void(0);" onclick="insertQ(curover);" class="a555" style="text-decoration: underline;">在此题后插入新题</a></div>
                            <div style="clear: none;" class="spanRight">
                                <ul class="stuff">
                                    <li><a href="javascript:void(0);" onclick="editQ(this);" title="您也可以双击题目来进行编辑"><span class="design-icon design-edit"></span><span>编辑</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.copyQ();" title="复制此题"><span class="design-icon design-copy"></span><span>复制</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.deleteQ();" title="删除此题"><span class="design-icon design-delete"></span><span>删除</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveUp();" title="将此题上移"><span class="design-icon design-up"></span><span>上移</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveDown();" title="将此题下移"><span class="design-icon design-down"></span><span>下移</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveFirst();" title="将此题移动到第一题"><span class="design-icon design-first"></span><span>最前</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveLast();" title="将此题移动到最后一题"><span class="design-icon design-last"></span><span>最后</span></a></li>
                                    <div style="clear: both;"></div>
                                </ul>
                            </div>
                            <div style="clear: both;"></div>
                        </div>
                    </div>

                    <%}
                      else if (Convert.ToInt32(Eval("questiontypeid")) == 3)
                      {%>

                    <div style="visibility: visible;" tabindex="-1" class="div_question div_question_mouseout">
                        <div class="div_preview">
                            <div class="div_title_question_all">
                                <div class="div_topic_question">1.</div>
                                <div class="div_title_question"><span><%# Eval("questionname") %></span></div>
                                <div style="clear: both;"></div>
                            </div>
                            
                            <div class="div_ins_question"></div>
                            <div class="spanLeft" style="height: 18px;">
                                <div style="clear: none; display: none;" class="div_ins_question spanLeft">*此题设置了跳转逻辑</div>
                                <div style="clear: none; display: none;" class="div_ins_question spanLeft"></div>
                            </div>
                            <div style="clear: none; display: none;" class="div_ins_question spanLeft"><a href="javascript:void(0);" onclick="insertQ(curover);" class="a555" style="text-decoration: underline;">在此题后插入新题</a></div>
                            <div style="clear: none;" class="spanRight">
                                <ul class="stuff">
                                    <li><a href="javascript:void(0);" onclick="editQ(this);" title="您也可以双击题目来进行编辑"><span class="design-icon design-edit"></span><span>编辑</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.copyQ();" title="复制此题"><span class="design-icon design-copy"></span><span>复制</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.deleteQ();" title="删除此题"><span class="design-icon design-delete"></span><span>删除</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveUp();" title="将此题上移"><span class="design-icon design-up"></span><span>上移</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveDown();" title="将此题下移"><span class="design-icon design-down"></span><span>下移</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveFirst();" title="将此题移动到第一题"><span class="design-icon design-first"></span><span>最前</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveLast();" title="将此题移动到最后一题"><span class="design-icon design-last"></span><span>最后</span></a></li>
                                    <div style="clear: both;"></div>
                                </ul>
                            </div>
                            <div style="clear: both;"></div>
                        </div>
                    </div>

                    <%}
                      else if (Convert.ToInt32(Eval("questiontypeid")) == 4)
                      {%>

                    <div style="visibility: visible;" tabindex="-1" class="div_question div_question_mouseout">
                        <div class="div_preview">
                            <div class="div_title_question_all">
                                <div class="div_topic_question">1.</div>
                                <div class="div_title_question"><span><%# Eval("questionname") %></span></div>
                                <div style="clear: both;"></div>
                            </div>
                            
                            <div class="div_ins_question"></div>
                            <div class="spanLeft" style="height: 18px;">
                                <div style="clear: none; display: none;" class="div_ins_question spanLeft">*此题设置了跳转逻辑</div>
                                <div style="clear: none; display: none;" class="div_ins_question spanLeft"></div>
                            </div>
                            <div style="clear: none; display: none;" class="div_ins_question spanLeft"><a href="javascript:void(0);" onclick="insertQ(curover);" class="a555" style="text-decoration: underline;">在此题后插入新题</a></div>
                            <div style="clear: none;" class="spanRight">
                                <ul class="stuff">
                                    <li><a href="javascript:void(0);" onclick="editQ(this);" title="您也可以双击题目来进行编辑"><span class="design-icon design-edit"></span><span>编辑</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.copyQ();" title="复制此题"><span class="design-icon design-copy"></span><span>复制</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.deleteQ();" title="删除此题"><span class="design-icon design-delete"></span><span>删除</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveUp();" title="将此题上移"><span class="design-icon design-up"></span><span>上移</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveDown();" title="将此题下移"><span class="design-icon design-down"></span><span>下移</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveFirst();" title="将此题移动到第一题"><span class="design-icon design-first"></span><span>最前</span></a></li>
                                    <li><a href="javascript:void(0);" onclick="curover.moveLast();" title="将此题移动到最后一题"><span class="design-icon design-last"></span><span>最后</span></a></li>
                                    <div style="clear: both;"></div>
                                </ul>
                            </div>
                            <div style="clear: both;"></div>
                        </div>
                    </div>

                    <%}
                    %>
                    
                </ItemTemplate>
            </asp:Repeater>

我在网上找了找解决办法,都是告诉我在Item_databound()事件中写,然后输出Html代码,但是在Html代码中写的话,我里面嵌套的repeater怎么办。。。。不可能直接输出吧。。。

羽商宫的主页 羽商宫 | 老鸟四级 | 园豆:2490
提问于:2014-04-09 13:00
< >
分享
所有回答(2)
0

控件数据绑定项是不允许这样的,用foeach做或者自己写个控件再或者后台写方法拼接HTML。。

兜兜里没有药 | 园豆:202 (菜鸟二级) | 2014-04-09 13:13
0

看你的这个Repeater有些复杂啊,还是在后台获取数据,前台用javascript模板引擎(artTemplate)进行处理吧

秋壶冰月 | 园豆:5903 (大侠五级) | 2014-04-09 13:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册