none
checkbox for DB2 "bool" form view edit field? RRS feed

  • Question

  • I've been working a little bit with the Scaffolding and how to make a nice DB manager using the ADO.net controls and such. I ran thru the basic tutorials and such and got myself a nice little site using my own DB2 database. (very tricky setup btw for those non SQL DBs...)

    One thing that SQL has that DB2 doesn't have is a field type of "Boolean". So we're having to make a backwards method that'll read a string value "Y" or "N" as the checked / not checked for a checkbox from a dynamic control. The problem I'm having is the Dynamic Control doesn't seem to have a .value or any method that'll allow me to read what that particular cell's value is that I can read into the code to do the following: 

    if (dynamicControl.Value == "Y") 
    chkBox.checked = true".

    It would be real good if someone with some DB2 setup experience lets me know there's a way to make a boolean field in DB2 so I can just go back to the datbase and make the field a bool instead of having to do all this. In the meantime this is all I have to work with. My DB2 experience isn't great at all so if someone with DB2 experience does see this and can make a post within the next few days then great.

    Maybe I'm going about this all wrong. If there's any suggestions please let me know. I'm a very novice programmer so please be patient with questions and try to be descriptive in your explainations please. Preferred language is C#. Thanks

    Monday, February 20, 2012 7:48 PM

Answers

  • With some help from my peers we were able to resolve the error using the following code:

    <asp:CheckBox ID="checkbox1" Checked='<%# Eval("COLUMN_NAME_HERE").ToString().Equals("Y") %>' runat="server" />

    At least with that we can now display the checkboxes properly based on the information we got from the database. What we need now is to make it so that when the user clicks the "update" button at the bottom, based on the checked or unchecked it'll post back to that databound item a "Y" for checked and "N" for unchecked and update the database with that value.

    • Marked as answer by GokouZWAR Monday, March 12, 2012 6:16 PM
    • Unmarked as answer by GokouZWAR Monday, March 12, 2012 6:16 PM
    • Marked as answer by GokouZWAR Tuesday, March 13, 2012 3:16 PM
    Monday, March 12, 2012 6:15 PM

All replies

  • Hi GokouZWAR,

    Welcome!

    I think your post is off-topic here. For how to retrieve Dynamic Control you should post in ASP.NET Forums, here is a link and hope it helps :http://forums.asp.net/t/1720652.aspx/1

    To tell you truth, I'm not familiar with DB2, but I found a link here for new data types in DB2, so I suggest you to repost your question here: http://www.ibm.com/developerworks/forums/db2_forums.jspa thanks for understanding.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 21, 2012 3:33 AM
    Moderator
  • Well my main question was not about DB2, but that did provide some help on setting up DB2 with a boolean data column so maybe that'll get me some progress there. However, my problem, even if I can get the boolean datatype setup still remains:

    How do I reference the value of a dynamic control that is in an ADO.Net data model that is connected to a DB2 database. What I'm trying to do is say whatever the dynamic control's value is, how can I reference the value of it? The link you provided to ASP.net was for a dynmically created dynamic control which is not the case here. I'm using a static created Dynamic Control in a formview that is created by using the webform creator and then connected to the DB2 using ADO.Net and LINQ, with EF objects. 

    Just about every time I post on here, this is the only response I get from you folks. "This is not the place to post this." You guys have like 1000 forums, for specific things and this one seemed to be the closest thing I have to where it SHOULD be.

    I'm using ADO, and EF 4 and LINQ queries in my site which seems to apply to this forum since what I ultimately need to do is retrieve data from a database. Be it, i retreive the "Y" / "N" from the Database's column by way of a LINQ query or by reading the dynamic control's value doesn't make much difference to me, hence why I posted here. I had hoped to get some sort of feedback that would guide me the correct direction for retrieving this kind of information and then allow me to take that information and set a checkbox on my form to .checked = true. The method of retrieval makes no difference to me as long as I can use the information to change the property on the checkbox object. Since this site uses ADO, LINQ and EF 4 to make this happen. It is on topic as far as I can tell...

    Obviously if the datatype in the DB2 is setup as a boolean then maybe it'll auto detect that and change the field template it chooses to convey the data to the user which would ultimately solve my problem. So I will be looking into that further.
    • Edited by GokouZWAR Tuesday, February 21, 2012 3:01 PM
    Tuesday, February 21, 2012 2:58 PM
  • Hi GokouZWAR,

    You can retrieve the "Y"/"X" by EF 4 and Binding FormView to show records, your question is how to make the CheckBox checked or not, right? I think you can try to :

    <td class="ProductPropertyValue">
                        <asp:CheckBox ID="CheckBox1" runat="server" Enabled="false"
                          Checked='<%# Eval("Discontinued").ToString()=="Y"? True: false %>' />
                    </td>
    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 22, 2012 9:24 AM
    Moderator
  • Hi,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 27, 2012 6:42 AM
    Moderator
  • Sorry it's taken me so long to get back to this thread. I had some surgery done and was unable to check these suggestions.

    The suggestion above about setting the checkbox based on the result sounds like it would work, however the problem is not just displaying but also retrieving the user's selection and making an alteration to the exisiting database based on that checkbox's selection. How would you go about doing that?

    I'll be testing this suggestion now to see if it works based on the database's information and I'll let you know if that worked shortly.

    Monday, March 12, 2012 1:49 PM
  • Ok so I'm probably missing something simple here but this is what I received after putting this code in:

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'True' does not exist in the current context

    Source Error:

    Line 106:</table>
    Line 107:<td class="ProductPropertyValue">
    Line 108:    <asp:CheckBox ID="CheckBox1" runat="server" Enabled="false" Checked='<%#Eval("Discontinued").ToString()=="Y"?True:False %>' />
    Line 109:</td>
    Line 110:

    Source File: c:\Documents and Settings\twalton\My Documents\Visual Studio 2010\Projects\PRMWebApplication\PRMWebApplication\DynamicData\EntityTemplates\Special_Item.ascx    Line: 108
    Monday, March 12, 2012 2:11 PM
  • With some help from my peers we were able to resolve the error using the following code:

    <asp:CheckBox ID="checkbox1" Checked='<%# Eval("COLUMN_NAME_HERE").ToString().Equals("Y") %>' runat="server" />

    At least with that we can now display the checkboxes properly based on the information we got from the database. What we need now is to make it so that when the user clicks the "update" button at the bottom, based on the checked or unchecked it'll post back to that databound item a "Y" for checked and "N" for unchecked and update the database with that value.

    • Marked as answer by GokouZWAR Monday, March 12, 2012 6:16 PM
    • Unmarked as answer by GokouZWAR Monday, March 12, 2012 6:16 PM
    • Marked as answer by GokouZWAR Tuesday, March 13, 2012 3:16 PM
    Monday, March 12, 2012 6:15 PM