如何获取字符串中的复选框值 [英] how to get checkbox value in a string

查看:70
本文介绍了如何获取字符串中的复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我使用复选框列表,其中选中了多个复选框,
当我保存记录it item.selected显示为false.

如何解决,
这是html代码:-

 <   asp:CheckBoxList     ID   ="   ="span>    runat   =" 服务器"  DataTextField   附件代码" 
                     span>                                                                                                  ="   AccessoryID"  CellSpacing   ="     CellPadding   ="    ="  
                     span>                                                                                                  ="   3" 宽度  ="     RepeatDirection   =" 水平" >  EnableViewState =" false
<  /asp:CheckBoxList&  > 

如何解决



这是代码背后的代码:-



< pre lang =& quot; vb& quot;" Dim strAcc As String = String.Empty
               对于lstAccessories.Items中的每个项目
                   昏暗的objCAccessory作为新的CAccessoryCodes
                   如果项目.则选择
                       objCAccessory.AccessoryID = item.value
                       &#39; objCAccessory.AccessoryCode = objCAccessory.AccessoryCode +&,& amp; quot; + item.Text
                       objCAccessory.AccessoryCode = item.Text
                       如果objCAccessory.AccessoryCode& lt;& gt;那没事了
                           strAcc = IIf(strAcc = String.Empty,objCAccessory.AccessoryCode,strAcc +& amp;,& amp;" + objCAccessory.AccessoryCode)
                       万一

                       &#39;如果AccessoryCodes =&& amp; quot;然后
                       &#39;附件代码= item.value
                       &#39;其他
                       &#39;附件代码=附件代码& amp; & amp; quot;& amp; amp; amp; amp; quot; & amp; amp; amp; item.value
                       &#39;如果结束
                       &#39; objCWOrder.objHandset.
                       objCWOrder.Accessories.Add(objCAccessory)
                   万一

               Next& lt;/pre& gt; <  /pre  >  

解决方案

如果在运行此代码之前绑定到数据源,它将重置所有选择.

如果您的复选框列表数据绑定代码处于Page.IsPostback条件,请检入页面加载.
试试:

 如果(IsPostback)
  ' 复选框列表数据绑定代码
结束 如果 


我没有让您知道您在说什么...
请重写您的问题,并明确说明您真正需要什么.

当然,我会帮助您.


Dear All,

i use check box list in which check several checkbox,
when i save record the it item.selected show false .

how to solve,
here is html code:-

<asp:CheckBoxList ID="lstAccessories" runat="server" DataTextField="AccessoryCode"

                                                                DataValueField="AccessoryID" CellSpacing="5" CellPadding="30" RepeatLayout="Table"

                                                                RepeatColumns="3" Width="95%" RepeatDirection="Horizontal" >EnableViewState="false"
</asp:CheckBoxList&>

how to solve it 



here is codeBehind code:-



&lt;pre lang=&quot;vb&quot;&gt;Dim strAcc As String = String.Empty
               For Each item In lstAccessories.Items
                   Dim objCAccessory As New CAccessoryCodes
                   If item.Selected Then
                       objCAccessory.AccessoryID = item.value
                       &amp;#39;objCAccessory.AccessoryCode = objCAccessory.AccessoryCode + &amp;quot;,&amp;quot; + item.Text
                       objCAccessory.AccessoryCode = item.Text
                       If objCAccessory.AccessoryCode &amp;lt;&amp;gt; Nothing Then
                           strAcc = IIf(strAcc = String.Empty, objCAccessory.AccessoryCode, strAcc + &amp;quot;,&amp;quot; + objCAccessory.AccessoryCode)
                       End If

                       &amp;#39;If AccessoryCodes = &amp;quot;&amp;quot; Then
                       &amp;#39;    AccessoryCodes = item.value
                       &amp;#39;Else
                       &amp;#39;    AccessoryCodes = AccessoryCodes &amp;amp; &amp;quot;,&amp;quot; &amp;amp; item.value
                       &amp;#39;End If
                       &amp;#39;objCWOrder.objHandset.
                       objCWOrder.Accessories.Add(objCAccessory)
                   End If

               Next&lt;/pre&gt;</pre>

解决方案

If you bind to your data source before running this code, it will reset all your selections.


Check in your pageload if you have put the checkboxlist databind code with Page.IsPostback condition.
Try:

If (IsPostback)
  'checkboxlist databind code
End If


I didn''t get you what you are talking about...
Please rewrite your question and mention clearly what exactly you need.

Sure I''ll help you.


这篇关于如何获取字符串中的复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆