Tag Archives: ASP.Net

Passing Value from .aspx page to user control using C#/ ASP.Net

Step1: Create property on User Control for setting and getting a value.

public Guid? ToRoleID
if (ViewState["idRole"] == null)
return Guid.Empty;
return Guid.Parse(ViewState["idRole"].ToString());
set { ViewState["idRole"] = value;}

Step2: Assign value to user control property in .aspx page

UCRoleMenuPermissions1.ToRoleID = idRole;

Step3: Override DataBind method for user control in .aspx page

public override void DataBind()
string To = ToRoleID.ToString();

Step4: Call User Control Data Bind method in .aspx page


Binding enum to RadioButtonList using C#/ ASP.Net

For example, we have an enum like this:

public enum Status

And we want to bind this with Radio Button List in C# / ASP.Net

Your .aspx will look like this:

<asp:RadioButtonList runat="server" ID="RadioButtonList1" RepeatDirection="Horizontal">

Whereas in .cs page you will bind it like this:

RadioButtonList rbl = (RadioButtonList)e.Row.FindControl("RadioButtonList1");

rbl.DataSource = Enum.GetValues(typeof(Status));