开发者

Automatically selected columns in ASPxGridView

I have 3 nested ASPxGridViews in my project. One is the master grid, the other ones are detail grid connected with primary/foreign key. When I click the new button in a detail grid, the columns in the form comes totally blank. But I want some columns which have ParentID to be automatically selected because I already selected that in its master grid. Here is a specific example:

I have a master grid which shows companies. This grid has a detail grid whi开发者_运维技巧ch shows departments belonging to these companies. I chose one of the companies and departments which blongs to it appeared in the detail grid. Then I cliked new button to create a new department data. But in the form, company combobox column is blank while it should be automatically selected. I have to choose the same company in this combobox again.

I couldn't find anything in DevExpress forums about this problem. I appreciate if you help.


update: to show using CellEditorInitialize:

protected void gvDepartments_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
    var grid = sender as ASPxGridView;

    if (grid == null || !grid.IsNewRowEditing)return;
    if (!e.Column.FieldName.Equals("Company")) return;

    (e.Editor as ASPxComboBox).SelectedValue =  grid.GetMasterRowKeyValue();
}

gridView.GetMasterRowKeyValue() on a detail grid gives you he KeyValue of the Master Grid. You can use this in HtmlRowCreated or CellEditorInitialize Event on your detail grid to get the Master key field (company id in yourcase), and have the combobox in the Edit Form selected as shown below:

protected void gvDepartments_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
{
    if (e.RowType == GridViewRowType.EditForm)
    {
        var gridView = sender as ASPxGridView;
        var companyID = gridView.GetMasterRowKeyValue();
        var ddlCompany = gridView.FindEditFormTemplateControl("ddlCompany") as ASPxComboBox;
        ddlCOmpany.SelectedValue = companyID;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜