Ver Mensaje Individual
  #2 (permalink)  
Antiguo 13/12/2012, 11:09
Avatar de Dradi7
Dradi7
 
Fecha de Ingreso: junio-2008
Ubicación: Peru - Lima
Mensajes: 1.518
Antigüedad: 15 años, 10 meses
Puntos: 220
Respuesta: Problema al enlazar Dictionary con Datalist

Bueno

Me auto respondo ya lo resolví si alguno tiene el mismo problema paso la solución

Primero para recorrer el Value del Dictionary pueden usar un Control Repeater por ejemplo y para poder enlazarlo con el respectivo Valor deben usar el evento ItemDataBound

Código:
protected void catalogos_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            // se valida que sea de tipo item o item alternativo
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                // buscamos nuestro control repeater
                Repeater r = (Repeater)e.Item.FindControl("repeat");
                // recuperamos el valor del DataItem y lo convertimos en un objeto de tipo KeyValuePair (Key y Value)
                System.Collections.Generic.KeyValuePair<string, cb.Catalogo[]> kv = (System.Collections.Generic.KeyValuePair<string, cb.Catalogo[]>)e.Item.DataItem;
                // Como el value es una lista o array lo enlazamos directamente al repeater y listo
                r.DataSource = kv.Value;
                r.DataBind();
            }
        }
En tu ASPX seria algo como esto

Código:
<asp:DataList ID="catalogos" runat="server">
 <HeaderTemplate>
     <tr>
        <td>Key</td>
        <td>Value1</td>
        <td>Value2</td>
       <td>Value3</td>
     </tr>
</HeaderTemplate>
<ItemTemplate>
     <tr>
           <td><%# Eval("Key") %></td>
           <asp:Repeater ID="repeat" runat="server">
                        <ItemTemplate>
                            <td>
                                <%# Eval("NombreCampo") %>
                            </td>
                        </ItemTemplate>
                    </asp:Repeater>
     </tr>
</ItemTemplate>
</asp:DataList>
Saludos
__________________
La clave de todo triunfador es eliminar todas sus excusas y sus limitaciones