chamara
chamara

Reputation: 12711

Kendo Grid edit popup - Set default TextBox text

I'm trying to set a default value in Kendo Grid edit popup. It's not showing. I tried setting the value with Jquery and model default value also but nothing works.

@Html.TextBoxFor(model => model.CountryCode, new { style="width:25px",@value="+94" })

Upvotes: 0

Views: 2197

Answers (4)

Sven
Sven

Reputation: 2505

The DefaultValue works only for static default values. But what to do if one likes to have dynamic default values, e.g. when the user selects a value from a DropDownList. I have no idea so far.

Upvotes: 0

cah1r
cah1r

Reputation: 1959

@chamara have you tried using .DefaultValue() in your grid ? This works for me.

Like this?

@(Html.Kendo().Grid(Model)
.Name("grid")
.Columns(columns =>
{

    columns.Bound(p => p.UserName);

})
    .ToolBar(toolbar => toolbar.Create().Text("Add"))
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("template"))
.DataSource(dataSource => dataSource
    .Ajax()
    .Model(model =>
        {
            model.Id(p => p.ID);
            model.Field(f => f.UserName).DefaultValue("+94");
        })
        .Read(read => read.Action(" ", " "))
        .Create(update => update.Action(" ", " "))
        .Update(update => update.Action(" ", " "))
        .Destroy(update => update.Action(" ", " "))
))

The defaultValue should be visible in your pop up.

Upvotes: 0

Saranga
Saranga

Reputation: 3228

Try this;

@Html.TextBoxFor(model => model.UserName, new { style = "width:25px", @Value = "+94" })

Letter V should be in upper-case in @Value = "+94" .

Upvotes: 1

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18873

Instead giving @Html.TextBoxFor value with @value="+94" as shown in your question just put

value "+94" in CountryCode property from controller side,this problem you are getting because

you are using strongly typed TextBox here.

Upvotes: 0

Related Questions