Tuesday, 14 May 2013

radio button list ( load enum values)

 c# coding

private void FillVoucherList()
    {
        rbtnlVoucherType.DataSource = System.Enum.GetValues(typeof(VoucherTypes));
        rbtnlVoucherType.DataBind();
        rbtnlVoucherType.SelectedValue = VoucherTypes.Journal.ToString(); //it is the default selection of vouchertype as "Journal"                 
    }// rbtnlVoucherType is the radio button list

Asp .net coding

  <tr>
                        <td class="captionColumn">
                            Status
                        </td>
                        <td>
                            :
                        </td>
                        <td>
                            <asp:RadioButtonList ID="rbtnlStatus" runat="server" RepeatDirection="Horizontal"
                                AutoPostBack="True">
                            </asp:RadioButtonList>
                        </td>
                    </tr>

Enum declaration

 public partial class Voucher
    {

        public VoucherTypes VoucherType
        {
            get { return (VoucherTypes)this.VoucherTypeId; }//id value in database field
            set { this.VoucherTypeId = (int)value; }
        }
    }
  
    public enum VoucherTypes
    {
        Journal = 0,
        Payment = 1,
        Receive = 2,
        Contra = 3,       
    }