Lincoln Pires
Lincoln Pires

Reputation: 348

Fill GridViewDataComboBoxColumn using value of the aspxgridview

I'm a novice C# programmer (about 6 months) and I'm using DevExpress components in my current work with ASP.NET.

I have no idea about fill a combox that is inside my grid. The problem is basically this: For each row in the grid I have a title / billet to show and in one column I have the list of bank accounts of when this title / billet was paid. I need to show at least one record where they exist, or empty when the title / billet has not yet been paid.

I looked out some examples and threads here in the site, I tried to implement but nothing that brought me some effective result.

The aspx looks like this one: `

<dx:ASPxGridView ID="devGridView" ClientInstanceName="devGridView" runat="server"
   AutoGenerateColumns="False" EnableCallBacks="False" KeyFieldName="ID_TITULO"
    Width="100%" DataSourceID="odsTitulosReceber">
   <Settings ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFooter="true" ShowFilterRow="true" />
   <SettingsBehavior AllowFocusedRow="true" />
   <SettingsDetail ShowDetailRow="true" />
   <SettingsPager PageSize="100">
   </SettingsPager>
   <ClientSideEvents RowClick="behavior.rowClick" />
   <Columns>
        <dx:GridViewDataTextColumn FieldName="ID_DOCUMENTO_FISCAL" Caption="Doc. Fiscal"
         Width="70px">
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="DS_PESSOA" Caption="Pessoa">
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="ST_TITULO" Caption="Situação">
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="DT_EMISSAO" Caption="Emissão">
          <PropertiesTextEdit DisplayFormatString="dd/MM/yyyy">
          </PropertiesTextEdit>
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="DT_VENCIMENTO" Caption="Vencimento">
          <PropertiesTextEdit DisplayFormatString="dd/MM/yyyy">
          </PropertiesTextEdit>
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="DT_PAGAMENTO" Caption="Pagamento">
          <PropertiesTextEdit DisplayFormatString="dd/MM/yyyy">
          </PropertiesTextEdit>
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="VL_TITULO" Caption="Valor" Width="110px">
          <PropertiesTextEdit DisplayFormatString="c">
          </PropertiesTextEdit>
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="VL_PAGO" Caption="Valor Pago" Width="110px">
          <PropertiesTextEdit DisplayFormatString="c">
          </PropertiesTextEdit>
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="VL_SALDO" Caption="Valor Saldo" Width="110px">
          <PropertiesTextEdit DisplayFormatString="c">
          </PropertiesTextEdit>
        </dx:GridViewDataTextColumn>
        <bold><dx:GridViewDataComboBoxColumn Caption="Pagamento Realizado" FieldName="CONTAS" >
          <PropertiesComboBox TextField="DESCRIPTION" ValueField="ID">
          </PropertiesComboBox>
        </dx:GridViewDataComboBoxColumn></bold>
        <dx:GridViewDataTextColumn FieldName="ID_TITULO" Caption="Título">
        </dx:GridViewDataTextColumn>
  </Columns>
</dx:ASPxGridView>

`

To fill the combo "Pagamento Realizado" I have five tables to go through filtering the data to get the accounts. The schema: title > movement_title < financial_movement > content_movement < bank_account Where title and financial_movement send the IDs to movement_title and so on about the ">" "<" signals... So, I have a list with repeated Titles and repeated Accounts. In codebehind I can do this query (using linq) to get the specified account that correspond to the correct title:

`

(...)
from ti in data.FINANCEIRO_TITULOs // TITULOS
join mt in data.FINANCEIRO_MOVIMENTOS_TITULOs on ti.NR_SEQ_TITULOS_FITI equals mt.NR_SEQ_TITULOS_FITI // MOVIMENTO_TITULOS
join mv in data.FINANCEIRO_MOVIMENTOs on mt.NR_SEQ_MOVIMENTO_FINANCEIRO_FIMF equals mv.NR_SEQ_MOVIMENTO_FINANCEIRO_FIMF // MOVIMENTOS
join cm in data.FINANCEIRO_CONTEUDO_MOVIMENTOs on mv.NR_SEQ_MOVIMENTO_FINANCEIRO_FIMF equals cm.NR_SEQ_MOVIMENTO_FINANCEIRO_FIMF // CONTEUDO_MOVIMENTOS
join co in data.FINANCEIRO_CONTAs on cm.NR_SEQ_CONTAS_FICO equals co.NR_SEQ_CONTAS_FICO // CONTAS

where
ti.TP_CREDITO_DEBITO_FITI == 2 && // credito
ti.ST_SITUACAO_FITI == 3 &&// baixado
ti.NR_SEQ_TITULOS_FITI.Equals(idTitulo)
select (...)

`

I need some help to do the fill. Please, if someone can help me, I am here to discuss... Thanks.

Upvotes: 2

Views: 6075

Answers (1)

Lincoln Pires
Lincoln Pires

Reputation: 348

Here's my temporary solution...

I put on the ASPx the following in my GridView Columns

<dx:GridViewDataColumn Caption="Pagamento Recebido" FieldName="CONTA">
       <DataItemTemplate>
               <asp:DropDownList DataTextField="Description" runat="server">
               </asp:DropDownList>
       </DataItemTemplate>
</dx:GridViewDataColumn>

And in the event I put my query as datasource to the dropdown. Is a poor way cause the Page Load is very slow​ and each consult takes a lot of time.

protected void devGridView_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
{
    if (e.KeyValue != null) // avoid header and column name
    {
        ControlFinder<DropDownList> finder = new ControlFinder<DropDownList>();
        finder.FindChildControlsRecursive(e.Row);

        int idTitulo = e.GetValue("ID_TITULO").ToString().ToInt(); // necessary param
        using (ErpDataLinq data = new ErpDataLinq())
        {
            finder.FoundControls.Each(f =>
            {
                f.DataSource = (
                from ti in data.FINANCEIRO_TITULOs // TITULOS
                join mt in data.FINANCEIRO_MOVIMENTOS_TITULOs on ti.NR_SEQ_TITULOS_FITI equals mt.NR_SEQ_TITULOS_FITI // MOVIMENTO_TITULOS
                join mv in data.FINANCEIRO_MOVIMENTOs on mt.NR_SEQ_MOVIMENTO_FINANCEIRO_FIMF equals mv.NR_SEQ_MOVIMENTO_FINANCEIRO_FIMF // MOVIMENTOS
                join cm in data.FINANCEIRO_CONTEUDO_MOVIMENTOs on mv.NR_SEQ_MOVIMENTO_FINANCEIRO_FIMF equals cm.NR_SEQ_MOVIMENTO_FINANCEIRO_FIMF // CONTEUDO_MOVIMENTOS
                join co in data.FINANCEIRO_CONTAs on cm.NR_SEQ_CONTAS_FICO equals co.NR_SEQ_CONTAS_FICO // CONTAS

                where
                ti.TP_CREDITO_DEBITO_FITI == (byte)FinancialBase.OperationType.Credit && // 2 - credito
                ti.ST_SITUACAO_FITI == (byte)Securities.Status.Closed && // 3 - baixado
                ti.NR_SEQ_TITULOS_FITI.Equals(idTitulo) // param
                select new { Description = co.NM_CONTA_FICO }).Distinct(); // distinct - to avoid duplicated values

                f.DataBind();
            });

        }
    }
}

Well, this solve my problem. The design / layout was lost. I will try now let the page beauty.

Thanks.

EDIT

For whom trying to understand the ControlFinder<T> and methods, here you have a resource that does the exactly behavior:

Upvotes: 1

Related Questions