How can assign variable for giving style background color to the column - html

I am trying to give the background color to the textbox conditionally but not working when I assign the variable columnstyle to the textbox. Here is the html code
var columnstyle = "text-align:center;vertical-align:central;background-color:#FFBF00";
if (Model.attendanceLogList[i].IsProtected)
{
isdisabled = true;
styleset = "background-color:#90EE90";
columnstyle = "text-align:center;vertical-align:central;background-color:#90EE90";
}
<td>
#Html.TextBoxFor(m => m.attendanceLogList[i].NormalHrs, new { #class = "form-control input-sm NormalHrsl", #style= "#(columnstyle)", #Value = Model.attendanceLogList[i].NormalHrs, onchange = "CalculateTotal()" })
<td>

You can try something like this
var columnstyle = Model.attendanceLogList[i].IsProtected == false ? "text-align:center;vertical-align:central;background-color:#FFBF00" : "text-align:center;vertical-align:central;background-color:#90EE90";
...

Related

#Html.DropDownListFor is showing a textbox before loaded

I have some problems with a multiple dropdownlist, while loading its showing a textbox and them it load the dropdownlist control:
this is the code in the View:
#Html.DropDownListFor(m => #m.SelectedInfractionsId,
new MultiSelectList(Model.InfractionList, "Value", "Text", #Model.SelectedInfractionsId),
new {
id = "SelectedInfractionsId",
#class = "form-control multiselect-dropdown",
multiple = "true",
data_placeholder = "Select Users"
})
This is the code in the Controller:
List<SelectListItem> Listofinfractions = new List<SelectListItem>();
var infractions = _context.InfractionsCategories.OrderByDescending(x => x.Id == 1);
foreach (var infraction in infractions)
{
Listofinfractions.Add(new SelectListItem()
{
Value = infraction.Id.ToString(),
Text = infraction.Name
});
}
Listofinfractions.Insert(0, new SelectListItem()
{
Text = "----Select----",
Value = string.Empty
});
Looks like the image down below:
DropDownListFor control while is loading
once is loaded the control looks like :
DropDownListFor control when is loaded

Unable to get data-value of div in HtmlForm Helper

I have an Html Form in a Wizard Wrapper with 2 for loops to display the model. Each time the "Next button" is clicked, I need to save the specific unit.
Here is a part of the form (it is huge so I didn't want to post more than is necessary):
#using (Html.BeginForm("SaveAssessmentUnitScores", "Management", FormMethod.Post, new { id = "SaveUnitScores" }))
{
#Html.HiddenFor(x => x.AttemptId)
#Html.HiddenFor(x => x.AssessorId)
#Html.HiddenFor(x => x.EmployeeCompanyId)
#Html.HiddenFor(x => x.RequirementId)
for (var i = 0; i < Model.Units.Count(); i++)
{
var block = Model.Units[i];
<div class="kt-wizard-v2__content" id="CurrentUnit" data-value="#block.UnitId" data-ktwizard-type="step-content" #(i == 0 ? "data-ktwizard-state='current'" : "")>
I need the "data-value" from the "CurrentUnit" div.
I tried using the wizard atrributes, then I tried putting an id on the div and using "getAttribute", neither works:
var form2 = $('#SaveUnitScores');
wizard = new KTWizard('kt_wizard_v2', options);
wizard.on('beforeNext', function (wizardObj) {
let sec = form2.find('[data-ktwizard-state="current"]');
let curPg = sec.attr("value");
var curUnit = form2.find('#CurrentUnit');
var unitId = curUnit.attr('data-value');
I do not receive any javascript errors but "unitId" and "curPage" are both empty strings. Any assistance is greatly appreciated.

How can I create a checkbox which renders both tick and cross symbol on consecutive clicks?

Need to create a checkbox component in React which puts tick mark on first check, turns it to cross mark on next click and then to blank on next consecutive click. How can I do that ? Below is my checkbox component:-
function getStyles(info) {
var style = {};
style.position = 'absolute';
style.width = '16px';
style.height = '16px';
style.margin = '4px 0 0';
style.background = '#EEE';
style.display = info.display;
return style;
}
const CheckboxValue = ({value, style}) => (
<input type="checkbox" style={style} value={value} />
);
export default (props) => {
return (
<CheckboxValue style={getStyles(props)} />
);
}

How to read value of selected item of drop down in Razor cshtml webmatrix

# {
var db = Database.Open("InventoryDB-D");
var listAgent = "SELECT catID,catName FROM InvCategoryTBLD";
List < SelectListItem > agentdropdownlistdata = new List < SelectListItem > ();
bool isSelected = false;
foreach(var item in db.Query(listAgent)) {
testvalue = item.catName;
agentdropdownlistdata.Add(new SelectListItem {
Text = item.catName,
Value = item.catID.ToString(),
Selected = isSelected
});
}
}
<div>
<form action="" method="post">
#Html.DropDownList("Agents", agentdropdownlistdata)
<input type="submit" value="Droplist" name="DroplistX" />
</form>
</div>
I need to read the value of the item selected in the dropdown list?
Create a variable and define it with a Request.Form instruction like this
if(isPost){
var Agents = Request.Form["Agents"];
}
When you'll click on submit, the variable will be set to what is selected inside your dropdownlist...

add into selectlist an item only if it doesn't exist into razor

I want to create selectlist dynamically by traversing child nodes with 'language' property. So, want to add this property value as a select list item only if it is not added previously.
I have following code.
#{
var litem = new List<SelectListItem>();
litem.Insert(0, new SelectListItem { Selected = true, Text = "All", Value = "" });
foreach (var i in Model.Content.Children.Where("Visible"))
{
//if (i.GetProperty("language").Value != "")
if (i.GetProperty("language").Value != "")
{
string langstr = i.GetProperty("language").Value.ToString();
SelectListItem item = new SelectListItem { Selected = false, Text = langstr, Value = langstr };
if ((!(litem.Contains(item))))
{
litem.Add(item);
}
}
}
var slang=new SelectList(litem);
#Html.DropDownList("drpLang", #slang, new { #class = "dropdown"})
}
But it is not able to check the same item present in list. What is going wrong?
if i understand you correctly, problem that litem contain duplicate,
this because you create new instance of object item and than check is list contain new instance (you not check for same property, you check for exactly same object).
change this line:
if ((!(litem.Contains(item))))
for something like this:
if (litem.All(i => i.Value != item.Value))
or if you need unique pair:
if (litem.All(i => i.Value != item.Value && i.Text!= item.Text))
also recommend move all login in controller and use viewbag for DropDownList