Hello,
to test the input I would like to set default values for the form. I do that in the OnItemCommand. The values for the properties "ShortName" and "LegalForm" are displayed, the other values are not.
Codebehind:
protected void rgCompanyies_OnItemCommand(object sender, GridCommandEventArgs e)
{
try
{
if (e.CommandName == "ViewCustomers")
{
Response.Redirect(EditUrl("Id", e.CommandArgument.ToString(), "ViewCustomer"));
}
if (e.CommandName == RadGrid.InitInsertCommandName)
{
if (IsDebugMode)
{
e.Canceled = true;
Hashtable values = new Hashtable();
string[] legalForms = { "GmbH", "AG", "Gbr", "OHG", "KG" };
Random rnd = new Random();
values["ShortName"] = $"A-Test{rnd.Next(10)}";
values["LegalForm"] = legalForms[rnd.Next(legalForms.Length)];
values["CompanyAddress.Street"] = $"Teststr. {rnd.Next(10)}";
values["CompanyAddress.Postalcode"] = $"{rnd.Next(10)}2345";
values["CompanyAddress.City"] = "Bonn";
values["CompanyPhone.Number"] = $"123456{rnd.Next(10)}";
values["CompanyEmail.Address"] = $"a.decke{rnd.Next(10)}@abc.de";
e.Item.OwnerTableView.InsertItem(values);
}
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
Views.ascx:
<EditFormSettings CaptionFormatString="Bearbeite <strong>{0}</strong>" EditFormType="Template" InsertCaption="Firma bearbeiten..." CaptionDataField="ShortName">
<FormTemplate>
<div id="main" class="container">
<div class="row mt-4">
<div class="col-12">
<div class="card">
<!--Firmendaten-->
<div class="card-header">
Firmendaten
</div>
<div class="card-body">
<div class="row g-2">
<!--CompanyTitle & CompanyTyp-->
<div class="col-md-6">
<label for="inputTitle" class="form-label-required">Title</label>
<asp:RequiredFieldValidator runat="server" ID="rfvInputCompanyName" ControlToValidate="tbCompanyName" Display="Dynamic" SetFocusOnError="True" CssClass="form-label-error float-end" ErrorMessage="Ein Firmenname wird erwartet!" ValidationGroup="vgCompany"/>
<asp:CustomValidator ID="cuvCompanyName" ControlToValidate="tbCompanyName" runat="server" Display="Dynamic" ErrorMessage="Firmenname bereits vorhanden!" CssClass="form-label-error float-end" SetFocusOnError="True" ValidationGroup="vgCompany" OnServerValidate="cuvInputCompanyName_OnServerValidate"/>
<asp:TextBox autofocus ID="tbCompanyName" Text='<%# Bind("ShortName") %>' runat="server" CssClass="form-control" ValidationGroup="vgCompany" TabIndex="10" required/>
</div>
<div class="col-md-6">
<label for="inputType" class="form-label">Firmentyp</label>
<asp:TextBox ID="tbCompanyLeagalForm" runat="server" Text='<%# Bind("LegalForm") %>' CssClass="form-control"/>
</div>
<!--Postalcode & Location-->
<div class="col-md-6">
<label for="inputPostalcode" class="form-label-required">PLZ</label>
<asp:RequiredFieldValidator runat="server" ID="rfvCompanyPostalcode" ControlToValidate="tbCompanyPostalcode" Display="Dynamic" SetFocusOnError="True" CssClass="form-label-error float-end" ErrorMessage="Eine PLZ wird erwartet!" ValidationGroup="vgCompany"/>
<asp:TextBox ID="tbCompanyPostalcode" Text='<%# Bind("CompanyAddress.Postalcode") %>' runat="server" CssClass="form-control" ValidationGroup="vgCompany" TabIndex="20" required/>
</div>
the values for ShortName and LegalForm are displayed correctly (show image). The CompanyAddress.Street, CompanyAddress.Postalcode, etc. values are not displayed. Why doesn't the binding work there?