How to bind Value to Radiogroup from database

  1. #1

    How to bind Value to Radiogroup from database

    can any one suggest me how to set Value on Radiogroup from database via controller

    here is my code

    @(Html.X().RadioGroup()
    .ID("RFont")
    .LabelWidth(90)
    .Width(300)
    .FieldLabel("Font")
    .AutomaticGrouping(false)
    .Items(
          Html.X().Radio().ID("RMedium").Name("RadioFont").InputValue("0").BoxLabel("Small"),
          Html.X().Radio().ID("RBigger").Name("RadioFont").InputValue("1").BoxLabel("Large")
          )
    )
    My value for the control will be either 0 or 1, suggest me how to set it on controller.
    Last edited by Dimitris; Feb 13, 2015 at 12:44 PM. Reason: formatting
  2. #2
    Hi,

    Before answering your question let me ask you what ext.net version are you working with?

    Your question refers to MVC razor but is posted in the 1.x forum. Since this is an unlikely combination, should we move it to the 2.x or 3.x forum and continue the discussion there?
  3. #3
    Hi Dimitris,

    I am sorry, i am using 2.5.2 version, mistakenly i have posted this in 1.x Help forum

    Please move it to 2.x or 3.x forum.
  4. #4
    There are a couple ways to answer your question.

    One option is to check a Radio in the Controller, for example:

    public ActionResult Index()
    {
        Radio radio = this.GetCmp<Radio>("RBigger");
        radio.Checked = true;
        return View();
    }
    Another way is to model your View and use RadioGroupFor. The Examples Explorer provides an example that demonstrates how to do it: http://mvc2.ext.net/#/Form_Groups/GroupFor/

    Hope it helps.
  5. #5
    Thank you Dimitris, it worked for me in the following code

    var values = new InsertOrderedDictionary<string, object>();
    values.Add("RadioFont", "Large");
    X.GetCmp<RadioGroup>("RFont").SetValue(values);
    Last edited by Dimitris; Feb 13, 2015 at 12:57 PM. Reason: formatting
  6. #6
    I think you meant to write "1" instead of "Large":

    var values = new InsertOrderedDictionary<string, object>();
    values.Add("RadioFont", "1");
    X.GetCmp<RadioGroup>("RFont").SetValue(values);
  7. #7
    Yes, it is, Thank you, got the solution.

Similar Threads

  1. Replies: 1
    Last Post: Nov 20, 2012, 9:27 AM
  2. Replies: 2
    Last Post: Oct 10, 2012, 6:27 PM
  3. Replies: 7
    Last Post: Mar 05, 2012, 8:21 AM
  4. Replies: 5
    Last Post: Jul 30, 2011, 6:40 PM
  5. [CLOSED] Load RadioGroup Item from database on Combo Select event
    By webclouder in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 16, 2010, 8:30 PM

Tags for this Thread

Posting Permissions