Preset radiobuttonlist with defualt value read from database

Last post 10-31-2006 1:39 AM by Gordon-Freeman. 1 replies.

Sort Posts:

  • Preset radiobuttonlist with defualt value read from database

    10-27-2006, 11:49 AM
    • Loading...
    • Balthazaar
    • Joined on 10-11-2004, 9:03 AM
    • Posts 12

    Hi there,

     this is the situation:

    I have a table that contains a bit field called "IsAllowed". It is either set to "False" or "True" or "NULL". Next, I have a gridview control that is bound to this table (actually it is more complicated, but for the sake of simplicity, this works as well ;-)).

    One column of this gridview originally contained a checkbox saying "Is allowed" and which was checked or not depending on the bit fields state. Now I need to have a radiobuttonlist instead that should contain the options "Is allowed" (which value is set to "True") and "Is not allowed" (which value is set to "False"). What I need to do now is bind these choices to the bit field so that if I add a new row, the radiobuttonlist is preset with what data is read from the table.

     Example:

    Table says: IsAllowed = True -> RadioButtonList says: Is allowed x   Is not allowed o

    Table says: IsAllowed = False -> RadioButtonList says: Is allowed o   Is not allowed x

    Table says: IsAllowed = NULL -> RadioButtonList says: Is allowed o   Is not allowed o

     

    Although this does not seem to be very hard, I have a problem. I added new items to the radiobuttonlist saying "Is allowed" (Value = True) and "Is not allowed" (Value = False). Then I created a query in my DAL that retrieves the value from the table. The result is either a True, a False or a NULL. Then I bound the resulting DataTable to the RadioButtonList control (everything through a ObjectDataSource control).

    And the result?

    Actually, the radiobuttonlist doesn't show the options I manually entered into the list, but only "o False" if the table says False, "o True" if the table says True and "o" if the table says NULL. Does anyone have a hint for me? I hope, I described the problem in an understandable way...

    Thank you very much and best regards,

    Christian.

    Filed under: , ,
  • Re: Preset radiobuttonlist with defualt value read from database

    10-31-2006, 1:39 AM
    Answer

    Remember you are using a RadioButtonList, which is grouped html <input type="radio"/>s, and that's the nature of html form only one radio should be selected in a group.

    So you cannot select both!

    You may try separate radios or CheckboxList, and add some javascript to make it perform like a redios group~

    你好! Just FYI o_O
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter