im using the Devexpress ASPxGridView for a project but are having problems to populate a custom EditForm with data.
It looks as follows
<Templates>
<EditForm>
Company Name:
<dx:ASPxTextBox ID="CompanyName" runat="server" Value="<% #Bind('CompanyName') %>" />
Parent:
<dx:ASPxListBox ID="ParentGuid" runat="server" Value="<% #Bind('ParentGuid') %>" />
</EditForm>
</Templates>
Normally I’d write something like
protected void ASPxGridView1_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
{
var CompanyList = db.companies.OrderBy(x => x.CompanyName).ToList();
ASPxListBox ParentGuid = (ASPxListBox)ASPxGridView1.FindControl("ParentGuid");
ParentGuid.DataSource = CompanyList;
ParentGuid.DataBind();
ASPxTextBox CompanyName = (ASPxTextBox)ASPxGridView1.FindControl("CompanyName");
CompanyName.Text = "Some company name";
}
But that wont work. Any advice where to start? The documentation doesn’t really cover custom forms that well :/
Thanks!
== UPDATE ==
Tried using the onhtmleditformcreated=”ASPxGridView1_HtmlEditFormCreated” with the method
protected void ASPxGridView1_HtmlEditFormCreated(object sender, ASPxGridViewEditFormEventArgs e)
{
Control CompanyName = ASPxGridView1.FindEditFormTemplateControl("CompanyName");
if (CompanyName != null)
{
ASPxTextBox CompanyNameEdit = CompanyName as ASPxTextBox;
CompanyName.Text = "Some Co";
}
}
The fact that I use Value=”<% #Bind(‘CompanyName’) %>” messes stuff up a bit. If i remove the Bind the boxes gets populated but then I have no way of fetching the data in them. Any way around this?
The answer is…
To populate a ASPxComboBox called CompanyList
BUT!
If you have a custom form like i had
you wont be able to populate it from code-behind, the #bind method is in the way and overwrite any other incoming value. However if you are not planning to populate them from code behind here is a neat trick to fetch the data…
But if you want to fill some of the form values from code-behind ensure there are no #bind methods in the EditForm
Populate as described in the top of this post and fetch the values like this
Have fun