简体   繁体   English

ASP.Net转发器响应控件绑定

[英]ASP.Net Repeater Responsive Controls Binding

I have ASP.Net controls for search attributes with check box options and ASP.NET repeater. 我具有用于带有复选框选项和ASP.NET中继器的搜索属性的ASP.Net控件。 For Responsive Design, I have same bindings in two different places to match the design. 对于自适应设计,我在两个不同的地方具有相同的绑定以匹配设计。

Here, CheckBoxList ID=Options1 & ID=Options2 both having same binding but the code will repeat. 在这里,CheckBoxList ID = Options1&ID = Options2都具有相同的绑定,但是代码将重复。 I have 400 lines to check the conditions for single binding. 我有400行用于检查单装订条件。 i have to duplicate all the codes again for the another view. 我必须为另一个视图再次复制所有代码。 Is there any way to optimize the code to single bind with both views handling. 有什么方法可以优化代码以对两个视图进行单绑定。 ( Avoid duplicate binding and checking)? (避免重复绑定和检查)?

// Desktop View

<div class="hidden-sm hidden-xs narrowSearch">
//Content
<asp:Repeater ID="rptAttributes1" runat="server" EnableViewState="true" OnItemDataBound="rptAttributes_ItemDataBound">
<ItemTemplate>
<li>
<div class="form">
<asp:CheckBoxList ID="Options1" runat="server" AutoPostBack="false" Visible="false"
DataTextField="EnOptionName" DataValueField="SubCategoryAttributeOptionID" Font-Strikeout="False" />
</div>
</li>
</ItemTemplate>
</asp:Repeater>
</div>

// Mobile view

 <div class="sec_left  hidden-lg hidden-md"> 
 <div class="moremenu narrowSearch">
//Content
 <asp:Repeater ID="rptAttribute2" runat="server" EnableViewState="true" OnItemDataBound="rptAttributes_ItemDataBound">
<ItemTemplate>
<li>
<div class="form">
<asp:CheckBoxList ID="Options2" runat="server" AutoPostBack="false" Visible="false"
DataTextField="EnOptionName" DataValueField="SubCategoryAttributeOptionID" Font-Strikeout="False" />
</div>
</li>
</ItemTemplate>
</asp:Repeater>
</div>
</div>

Code Behind: 背后的代码:

 CheckBoxList chklOptions1 = item.FindControl("Options1") as CheckBoxList;
 CheckBoxList chklOptions2 = item.FindControl("Options2") as CheckBoxList;

You can place your repeater (including the declarative code as well as what you have in the code-behind of your page) into a custom user control. 您可以将转发器(包括说明性代码以及页面代码背后的内容)放入自定义用户控件中。 Then you put the user control in each section (desktop and mobile) of your page. 然后,将用户控件放在页面的每个部分(台式机和移动设备)中。 This is the simplest way to avoid repeated code. 这是避免重复代码的最简单方法。 Having said this, since you've only provided part of the code that's in the code-behind class of your page, I can't speak to what changes might be required when you move the imperative code you have in your page's code-behind class to the user control. 话虽如此,由于您仅提供了页面代码隐藏类中的部分代码,因此,当您移动页面代码隐藏中的命令性代码时,我无法说出可能需要进行哪些更改用户控件的类。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM