Hi Everyone,
I need some help. I'm building a radgrid with ascx control like this demo Edit Form Type . However, I made some changes where I'm using Entity Framework to store information back to the database. I'm using the below code to capture the textbox and dropdownlist value and then passing them into my entity code.
This is where I need some help. Instead of capturing the textbox value directly, I want to create a property and apply some validation rule in the properties. Then I want to access these properties to get the values from the aspx.cs file. Instead of string CostCenterName = (userControl.FindControl("txtCostCenterName") as RadTextBox).Text, I need to access the properties.
Code Behind on the .ascx.cs file
Code Behind on .aspx.cs file
I need some help. I'm building a radgrid with ascx control like this demo Edit Form Type . However, I made some changes where I'm using Entity Framework to store information back to the database. I'm using the below code to capture the textbox and dropdownlist value and then passing them into my entity code.
This is where I need some help. Instead of capturing the textbox value directly, I want to create a property and apply some validation rule in the properties. Then I want to access these properties to get the values from the aspx.cs file. Instead of string CostCenterName = (userControl.FindControl("txtCostCenterName") as RadTextBox).Text, I need to access the properties.
Code Behind on the .ascx.cs file
public
string
CostCenterName
{
get
{
return
txtCostCenterName.Text;
}
}
Code Behind on .aspx.cs file
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
int
CostCenterNo = Int32.Parse((userControl.FindControl(
"txtCostCenterNo"
)
as
RadNumericTextBox).Text);
string
CostCenterName = (userControl.FindControl(
"txtCostCenterName"
)
as
RadTextBox).Text;
int
CostCenterType= Int32.Parse((userControl.FindControl(
"ddlCostCenterType"
)
as
RadDropDownList).SelectedValue);
string
UpdateBy = UserName;
DateTime UpdateDateTime = DateTime.Now;
var insertNew =
new
CostCenter
{
CostCenterNumber = CostCenterNo,
CostCenterName = CostCenterName,
CostCenterTypeID = CostCenterType,
UpdateBy = UpdateBy,
UpdateDateTime = UpdateDateTime
};
try
{
DbContext.AddToCostCenters(insertNew);
DbContext.SaveChanges();
SetMessage(
"Cost Center No "
+ CostCenterNo +
" was added!"
);
}