This is a migrated thread and some comments may be shown as answers.

Bind ImageUrl to GrindButtonColumn of DetailTables instead of MasterTableView

3 Answers 10 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mário
Top achievements
Rank 1
Mário asked on 25 Jun 2014, 02:34 PM
Hello,

I have this code and it does what i say in the title, but to a MasterTableView.

ASPX
<telerik:RadSplitter runat="server" ID="RSDocumentosDespesa" Width="100%" Height="100%" BorderSize="2">
      <telerik:RadPane runat="Server" ID="LeftPaneDocDespesa" Scrolling="None">
          <telerik:RadSplitter runat="server" ID="rsDocDespesaDetail" Width="100%" Height="100%" Orientation="Horizontal">
              <telerik:RadPane runat="Server" ID="TopPaneDocDespesaDetail" Scrolling="Both" Height="30%">
                  <telerik:RadGrid runat="server" ID="rgDocumentos" ShowStatusBar="false" ShowFooter="false" AutoGenerateColumns="false" OnSelectedIndexChanged="rgDocumentos_SelectedIndexChanged" OnItemCommand="rgDocumentos_ItemCommand" OnItemDataBound="rgDocumentos_ItemDataBound"
                      AllowSorting="false" AllowMultiRowSelection="false" AllowPaging="false" OnItemCreated="rgDocumentos_OnItemCreated" OnNeedDataSource="rgDocumentos_NeedDataSource" OnPreRender="rgDocumentos_PreRender" OnColumnCreated="rgDocumentos_ColumnCreated">
                      <MasterTableView DataKeyNames="DDR_Tipo_Doc, DDR_Cod, DDR_Intervencao_Cirurgica, EST_Designacao">
                          <Columns>
                              <telerik:GridBoundColumn HeaderText="Nr Ordem" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" DataField="DDD_Num_Ordem" />
                              <telerik:GridBoundColumn HeaderText="Nr Doc." ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" DataField="DDD_Num_Doc" />
                              <telerik:GridBoundColumn HeaderText="Data" DataFormatString="{0:dd/MM/yyyy}" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" DataField="DDD_Data" />
                              <telerik:GridButtonColumn HeaderText="" HeaderStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ButtonType="ImageButton" ImageUrl="Images/Botao/cancel.gif" UniqueName="Imagem"></telerik:GridButtonColumn>
                              <telerik:GridBoundColumn HeaderText="Estado" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" DataField="EST_Designacao" UniqueName="Estado" />
                              <telerik:GridBoundColumn HeaderText="Tipo" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" DataField="Tipo_Doc_Desc" />
                              <telerik:GridBoundColumn HeaderText="Valor" DataFormatString="{0:F2}" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataField="DDD_Valor" />
                              <telerik:GridBoundColumn HeaderText="Valor Reembolsar" DataFormatString="{0:F2}" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataField="DDR_Valor_Reeembolso" />
                              <telerik:GridBoundColumn HeaderText="Valor Subsistema" DataFormatString="{0:F2}" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataField="DDR_Valor_Ref_Subsistema" />
...

C#
protected void rgDocumentos_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           switch (item.GetDataKeyValue("EST_Designacao").ToString().ToLower())
           {
               case "para devolução":
                   item["Imagem"].Enabled = false;
                   item["Devolver"].Enabled = false;
                   (item["Imagem"].Controls[0] as ImageButton).ImageUrl = "Images/para_devolucao.gif";
                   break;
               case "análise concluída":
                   item["Imagem"].Enabled = false;
                   item["Processar"].Enabled = false;
                   (item["Imagem"].Controls[0] as ImageButton).ImageUrl = "Images/analise_concluida.gif";
                   break;
         ...


But now i want to do it in one DetailTable inside, and now in this ASPX:
                   <telerik:RadGrid ID="rgProcessos" runat="server" ShowStatusBar="true" ShowFooter="false" CssClass="RadGrid"
                        AutoGenerateColumns="false" AllowSorting="true" AllowMultiRowSelection="false"
                        AllowPaging="true" OnDetailTableDataBind="rgProcessos_DetailTableDataBind"
                        OnNeedDataSource="rgProcessos_NeedDataSource" OnItemCommand="rgProcessos_ItemCommand"
                        OnItemCreated="rgProcessos_ItemCreated" OnColumnCreated="rgProcessos_ColumnCreated"
                        AllowFilteringByColumn="true"
                        PageSize="100" OnPreRender="rgProcessos_PreRender">
                        <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" Position="Bottom" PagerTextFormat="páginas: {4} | página {0} de {1}, registo {2} a {3} de {5}" />
                        <MasterTableView DataKeyNames="PRC_Cod, Alerta" Name="Processos">
 
                            <DetailTables>
                                <telerik:GridTableView DataKeyNames="ADI_Cod" Name="Aditamentos" Width="100%" ShowFooter="false" AllowFilteringByColumn="false" AllowPaging="false">
                                    <DetailTables>
                                        <telerik:GridTableView DataKeyNames="EST_Designacao" Name="Documentos" Width="100%" AllowFilteringByColumn="false" AllowPaging="false">
                                            <Columns>
                                                <telerik:GridBoundColumn HeaderText="Nr Ordem" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" DataField="DDD_Num_Ordem" />
                                                <telerik:GridBoundColumn HeaderText="Nr Documento" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" DataField="DDD_Num_Doc" />
                                                <telerik:GridBoundColumn HeaderText="Data" DataFormatString="{0:dd/MM/yyyy}" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" DataField="DDD_Data" />
<%--                                                <telerik:GridButtonColumn HeaderText="" HeaderStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ButtonType="ImageButton" ImageUrl="Images/Botao/cancel.gif" UniqueName="Imagem"></telerik:GridButtonColumn>--%>
                                                <telerik:GridBoundColumn HeaderText="Estado" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" DataField="EST_Designacao" UniqueName="Estado" />

Can you please help me how to do it? It is doing the same thing but to the GridButtonColumn in the inner detail table instead of doing it to the GridButtonColumn in the MasterTableView.

Thanks,
Mário

3 Answers, 1 is accepted

Sort by
0
Mário
Top achievements
Rank 1
answered on 25 Jun 2014, 02:38 PM
Just an extra information: i used the same code to do it but it cant access item["Imagem"] table cell. It's the same code behind with the same UniqueName.

Thanks.
0
Shinu
Top achievements
Rank 1
answered on 26 Jun 2014, 06:56 AM
Hi Mário,

When you want to access a detail table item, you have to use its Name property to identify the particular GridTableView and access the columns inside that as shown below.

C#:
protected void rgDocumentos_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Documentos")
 {
   GridDataItem dataItem = (GridDataItem)e.Item;
   //Condition
    {
     (dataItem["Imagem"].Controls[0] as ImageButton).ImageUrl = "Image/ImageName.gif";
    }
  }
}

Thanks,
Shinu
0
Mário
Top achievements
Rank 1
answered on 26 Jun 2014, 10:03 AM
Great Shinu! That solved what i wanted to do.

Thank you very much for your availability!

Regards,
Mário
Tags
Grid
Asked by
Mário
Top achievements
Rank 1
Answers by
Mário
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or