如何将bool类型转换为system.web.ui.webcontrols.checkbox [英] How do I convert type bool to system.web.ui.webcontrols.checkbox

查看:90
本文介绍了如何将bool类型转换为system.web.ui.webcontrols.checkbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个参赛表格和搜索页面。 (两个aspx文件)默认情况下,当有人查看条目页面时,它是空白的,并且它们输入与文本框,下拉列表和复选框相关的数据。



现在搜索页面允许用户搜索以前的条目并进行编辑。我的目的是使用户能够搜索先前的条目,选择一个条目,然后将它们带到预填充的条目页面(通过超链接)来编辑数据。



一切正常,但我不确定如何从我拉出的数据库中加载复选框。填写表格的代码如下:



I have an Entry form and search page. (both aspx files) By default when someone views the entry page it is blank and they enter the data related to the Textboxes, dropdownlists, and checkboxes.

Now the search page lets the user search previous entries and edit them as well. My go is to enable the user to search for previous entries, selects one, and then take them to the prefilled entrypage (via hyperlink) to edit the data.

Everything is working fine except for I'm unsure how to load the checkboxes from the database I'm pulling from. The code to Fill the form is below:

private void FillForm(int accountEntryID)
       {
           var loadAccountEntryByID = new AccountTrackerEntrySVC().LoadAccountEntryByID(accountEntryID);

            //Check if object is valid
           if (loadAccountEntryByID.AccountEntryID > 0)
           {
               uxMainFormPnl.Visible = true;

               uxAccountNumTxt.Text = loadAccountEntryByID.AccountEntryID.ToString();
               uxPhysicalLocationTxt.Text = loadAccountEntryByID.PhysicalLocationDesc;
               uxPasswordChangeFrequencyDescTxt.Text = loadAccountEntryByID.PasswordChangeFrequency;
               uxDataBeingTransferredDescTxt.Text = loadAccountEntryByID.DataBeingTransferredDesc;

               // DDL's: Data Choice, Type of Connection
               uxDataChoiceDdl.DataValueField = DataConverter.ObjectToString(loadAccountEntryByID.DataChoiceNum);
               uxTypeOfconnectionDescTxt.DataValueField = DataConverter.ObjectToString(loadAccountEntryByID.ConnectionTypeDesc);

               // Check boxes: Password Protected
               bool selected = false;
               if (PasswordProtectedCB.Checked == false)
               {   selected = false;


               }
               else
               {
                   selected = true;
                   PasswordProtectedCB = DataConverter.ObjectToBool(loadAccountEntryByID.PasswordProtected);//Error in title returned here.
               }



如果我能解决的话,很长一段时间:标题中列出的转换错误,我想我应该没问题。关于如何解决这个问题的任何想法?


Long story short if I can fix: the coversion error listed in the title, I think I should be fine. Any ideas on how to go about this?

推荐答案

转换的概念在这里是无稽之谈。控件不能是布尔值;它可以有描述状态的布尔值: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.checked(v = vs.110).aspx [ ^ ]。



-SA
The notion of "convert" is nonsense here. The control cannot be Boolean; it can have Boolean value describing the state: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.checked(v=vs.110).aspx[^].

—SA


你可以设置 CheckBox 。从您存储的值中检查属性。例如

you can set CheckBox.Checked property from the value you stored. for example
PasswordProtectedCB.Checked = DataConverter.ObjectToBool(loadAccountEntryByID.PasswordProtected)


这篇关于如何将bool类型转换为system.web.ui.webcontrols.checkbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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