Hallo Alex Wenig tststs im gegenteil genau das DANKE. Endlich einen knoten weniger. Zeit fuer urlaub...
Gruss Roman Pittroff Consulting Bangkok, Thailand >-----Original Message----- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED] On Behalf Of Alexander Zeitler >Sent: 22 April 2005 15:04 >To: [email protected] >Subject: RE: [Asp.net] Array an Datagrid..binde ? > > >Hallo, > >> >> Ich habe eine Class x und will diese in eine matrix reinschreiben. >> also matrix(x,y) = x >> >> Dieses soll dann an einem datagrid gebunden werden und um das ganze >> noch spanneder zu machen eine propertie aus dem Class >steuert das CSS >> der jeweiligen zelle. >> >> Habe das schon als collection versucht nur dann zeigt mir >das datagrid >> nur den count an. >> >> >> Irgend wie bekomme ich das heue nicht hin :-( > >Angenommen Du hast die Klasse Product: > > public class Product > { > private int id; > private string name; > private decimal unitPrice; > private bool isDiscontinued; > > public Product(int ID, string Name, decimal >UnitPrice, bool >IsDiscontinued) > { > this.ID = ID; > this.Name = Name; > this.UnitPrice = UnitPrice; > this.IsDiscontinued = >IsDiscontinued; > } > > > public int ID > { > get { > return id; > } > set { > id = value; > } > } > > > public string Name > { > get { > return name; > } > set { name = value; } > } > > > public decimal UnitPrice > { > get { > return unitPrice; > } > set { > unitPrice = value; > } > } > > > public bool IsDiscontinued > { > get { > return isDiscontinued; > } > set { > isDiscontinued = value; > } > } >} > >dann leitest Du Dir von ArrayList eine Custom Collection >ab: > > public class ProductsCollection: ArrayList { > public enum ProductsCollectionFields { > Name, > UnitPrice > } > > public void Sort(ProductsCollectionFields >sortField, bool >isAscending) { > switch (sortField) { > case ProductsCollectionFields.Name: > base.Sort(new >ProductNameComparer()); > break; > } > > if (!isAscending) base.Reverse(); > } > > private sealed class ProductNameComparer : IComparer { > public int Compare(object x, object y) { > Product first = (Product) x; > Product second = (Product) y; > return >first.Name.CompareTo(second.Name); > } > } > > private sealed class PriceComparer : IComparer { > public int Compare(object x, object y) { > Product first = (Product) x; > Product second = (Product) y; > return >first.UnitPrice.CompareTo(second.UnitPrice); > } > } > } > > >Das ganze kannst Du dann im DataGrid verwenden: > ><asp:DataGrid id="dgrProducts" runat="server" BorderColor="#CC9966" >BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" >AllowPaging="True" Width="500px" AutoGenerateColumns="False" >allowsorting="True"> ><SelectedItemStyle Font-Bold="True" ForeColor="#663399" >BackColor="#FFCC66"> </SelectedItemStyle> > ><ItemStyle ForeColor="#330099" BackColor="White"> </ItemStyle> > ><HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" >BackColor="#990000"> </HeaderStyle> > ><FooterStyle ForeColor="#330099" BackColor="#FFFFCC"> </FooterStyle> > ><Columns> ><asp:BoundColumn DataField="ID" HeaderText="ID"> <HeaderStyle >HorizontalAlign="Center"> </HeaderStyle> <ItemStyle >HorizontalAlign="Right"> </ItemStyle> </asp:BoundColumn> ><asp:templatecolumn sortexpression="name"> > <headerstyle horizontalalign="Center" /> > <headertemplate> > Name > <!--<asp:linkbutton id="lbtHeaderName" runat="server" >commandname="Sort">Produkt-Bezeichnung</asp:linkbutton>--> > </headertemplate> > <itemtemplate> > <%# DataBinder.Eval(Container, "DataItem.Name") %> > </itemtemplate> ></asp:templatecolumn> ><asp:BoundColumn DataField="UnitPrice" HeaderText="Einheitspreis" >DataFormatString="{0:c}" sortexpression="unitprice"> ><HeaderStyle HorizontalAlign="Center"> </HeaderStyle> > ><ItemStyle HorizontalAlign="Right"> ></ItemStyle> ></asp:BoundColumn> ><asp:TemplateColumn HeaderText="Abgekündigt"> ><HeaderStyle HorizontalAlign="Center"> </HeaderStyle> > ><ItemStyle HorizontalAlign="Center"> ></ItemStyle> > ><ItemTemplate> ><asp:CheckBox ID="chbDiscontinued" Runat="server" >Enabled="False"/> <!--Checked='<%# DataBinder.Eval(Container, >"DataItem.IsDiscontinued")%>'--> </ItemTemplate> ></asp:TemplateColumn> </Columns> > ><PagerStyle HorizontalAlign="Center" ForeColor="#330099" >BackColor="#FFFFCC" >Mode="NumericPages"> ></PagerStyle></asp:DataGrid> > >oder auch z.B. im ItemDataBound darauf zugreifen: > > private void dgrProducts_ItemDataBound(object >sender, DataGridItemEventArgs e) { > // Fill Checkboxes > if( e.Item.ItemType == ListItemType.Item || > e.Item.ItemType == >ListItemType.AlternatingItem) { > Product product = >(Product)e.Item.DataItem; > >((CheckBox)e.Item.Cells[3].Controls[1]).Checked = >product.IsDiscontinued; > } > } > >hoffe, das hilft ein wenig ;-) > >Gruss > >Alex > > >_______________________________________________ >Asp.net Mailingliste, Postings senden an: >[email protected] >An-/Abmeldung und Suchfunktion unter: >http://www.glengamoi.com/mailman/listinfo/asp.net > _______________________________________________ Asp.net Mailingliste, Postings senden an: [email protected] An-/Abmeldung und Suchfunktion unter: http://www.glengamoi.com/mailman/listinfo/asp.net
