Create Radio button List from the Model in MVC

Let’s suppose that we have a Model for the tbl_department and we want to render a radio button list for all departments. Take the following model as an example.

In the following article you will see that how to create a Radio button list in MVC. The article use the EmployeeDb sample SQL database( Download: scripts to create the EmlpoyeeDb SQL database) and MVC 4 framework with Razor engine view. Continue reading “Create Radio button List from the Model in MVC”

How to create Radio Buttons from a String Array in C#

This following example creates radio button controls and set their text from an array of strings programmatically. The example draws the radio button in vertical direction.

private void Form_load(object sender, EventArgs e)
{
    string[] string_Array = new string[3];
 
    string_Array[0] = "USA";
    string_Array[1] = "India";
    string_Array[2] = "Germany";
 
	DrawRadioButtons(string_Array);
}
 
private void DrawRadioButtons(string[] ArrayOfString)
{
    System.Windows.Forms.RadioButton[] btnRadio = new System.Windows.Forms.RadioButton[string_Array.Length];
 
    for (int i = 0; i < ArrayOfString.Length; ++i)
    {
        btnRadio[i] = new RadioButton();
        btnRadio[i].Text = ArrayOfString[i];
        btnRadio[i].Location = new System.Drawing.Point(10, 30 + i * 20);
        this.Controls.Add(btnRadio[i]);
    }
}

See the output on the windows form:
Continue reading “How to create Radio Buttons from a String Array in C#”