简体   繁体   中英

DevExpress GridView for MVC - How to set default value for template cell

In a Developer Express GridView in cshtml file I have a column declared as follows:

settings.Columns.Add(column =>
{
    column.FieldName = "DOCENTE_ID";
    column.Caption = "Docente";
    column.SetDataItemTemplateContent(container =>
    {
        var doc = DataBinder.Eval(container.DataItem, "DesDocente") as string;
        ViewContext.Writer.Write("{0}", doc);
    });

    column.SetEditItemTemplateContent(container =>
    {
        Html.RenderAction("TeachersPartial", new
        {
            bindingName = "DOCENTE_ID",
            esse3_id = DataBinder.Eval(container.DataItem, "DOCENTE_ID")
       });
    });
});

I have to set DOCENTE_ID default value to 39735.

This default value must come into play when the user does not select a value in the combo.

How can I do? Thanks in advance,

Simone

You can initialize a default value in the following manner:

column.SetEditItemTemplateContent(container =>
{
    object esse3_id_value_or_default = DataBinder.Eval(container.DataItem, "DOCENTE_ID") ?? 39735;
    Html.RenderAction("TeachersPartial", new
    {
        bindingName = "DOCENTE_ID",
        esse3_id = esse3_id_value_or_default
   });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM