locked
Using IF Statements inside webgrid column aspnet mvc c# RRS feed

  • Question

  • User-1453200658 posted

    Hi all,

    In MVC aspnet C# project I have setting an Webgrid.

    In edit web grid the value of the day_gv it's always null and required.

    But if the value of bool Truefalse is set to true I need set as "0000-00-00" the day_gv field.

    I have tried code below without success.

    enter image description here

    Can you help me?

    webGrid.Column(
    header: "day_gv",
    style: "day_gv",
    format: @<span>
        <span class="label">@item.day_gv</span>
        @item.Truefalse ? 
    <input class="text name" type="text" value="@item.day_gv" style="display:none" /> : 
    <input class="text name" type="text" value="0000-00-00" style="display:none" />
    </span>),
    Sunday, May 30, 2021 10:24 AM

Answers

  • User475983607 posted

    Edward Sheriff Curtis

    thanks fo reply, but I can't set the day_gv variable to 0000-00-00 because this value it may already have been inserted into the database when editing row on webgrid

    In this case I need show the value of day_gv variable and not default 0000-00-00 value.

    For this I need rendering two different inputs

    Your response makes no logical sense.   You're making a very simple programming construct overly complex.  The UI design should have one input which can have a variable value.  That's how inputs work.  

    Did you try a default value??? 

    public string day_gv {get; set;} = "0000-00-00";

    Or setting set the input value using Razor syntax.

    value='@(item.Truefalse ? "0000-00-00" : item.day_gv)'

    Can you explain what you mean by because this value it may already have been inserted into the database when editing row on webgrid?  Why are you unable to fetch the actual value form the database???  Also is day_gv a string?  DateTime???

    • Marked as answer by An0nym0u5User Tuesday, June 22, 2021 12:00 AM
    Sunday, May 30, 2021 12:30 PM

All replies

  • User475983607 posted

    Rather than rendering two different inputs, just set the day_gv variable to 0000-00-00.  This can be done in the model by setting a default value. 

    Sunday, May 30, 2021 10:39 AM
  • User-1453200658 posted

    Rather than rendering two different inputs, just set the day_gv variable to 0000-00-00.  This can be done in the model by setting a default value. 

    thanks fo reply, but I can't set the day_gv variable to 0000-00-00 because this value it may already have been inserted into the database when editing row on webgrid

    In this case I need show the value of day_gv variable and not default 0000-00-00 value.

    For this I need rendering two different inputs

    Sunday, May 30, 2021 11:57 AM
  • User475983607 posted

    Edward Sheriff Curtis

    thanks fo reply, but I can't set the day_gv variable to 0000-00-00 because this value it may already have been inserted into the database when editing row on webgrid

    In this case I need show the value of day_gv variable and not default 0000-00-00 value.

    For this I need rendering two different inputs

    Your response makes no logical sense.   You're making a very simple programming construct overly complex.  The UI design should have one input which can have a variable value.  That's how inputs work.  

    Did you try a default value??? 

    public string day_gv {get; set;} = "0000-00-00";

    Or setting set the input value using Razor syntax.

    value='@(item.Truefalse ? "0000-00-00" : item.day_gv)'

    Can you explain what you mean by because this value it may already have been inserted into the database when editing row on webgrid?  Why are you unable to fetch the actual value form the database???  Also is day_gv a string?  DateTime???

    • Marked as answer by An0nym0u5User Tuesday, June 22, 2021 12:00 AM
    Sunday, May 30, 2021 12:30 PM