g_r_a_robinson Posted January 13, 2004 Posted January 13, 2004 I want my datagrid to display my dataset in the following way: Note Added Date By Who Action 14/01/2004 9:07:29 AM George Robinson Quote Comments go here 13/01/2004 4:23:24 PM George Robinson Installation More comments go here 13/01/2004 4:23:20 PM George Robinson Installation Even more comments go here Thing is, i'm quite new and I'm having little success. Basically I want the first three column items in the row header and the last one, the description in the main body, as above. Heres my code HTML <asp:datagrid id="NoteGrid_GRD" style="Z-INDEX: 104; LEFT: -1px; POSITION: absolute; TOP: 422px" runat="server" CellPadding="3" BorderWidth="1px" BorderStyle="None" BorderColor="#E7E7FF" GridLines="Horizontal" BackColor="White" OnItemDataBound="NoteGrid_GRD_ItemDataBound" AutoGenerateColumns="False"> <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle> <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle> <ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle> <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle> <Columns> <asp:BoundColumn DataField="Date" HeaderText="Note Added Date"></asp:BoundColumn> <asp:BoundColumn DataField="ByWho" HeaderText="By Who"></asp:BoundColumn> <asp:BoundColumn DataField="FK_Action_Performed" HeaderText="Action"></asp:BoundColumn> <asp:BoundColumn DataField="Note_Description"></asp:BoundColumn> </Columns> <PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF" Mode="NumericPages"></PagerStyle> </asp:datagrid> And my Code Behind noteView = noteData.Tables[NotesData.NOTES_TABLE].DefaultView; NoteGrid_GRD.DataSource = noteView; NoteGrid_GRD.DataBind(); public void NoteGrid_GRD_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.Header) { e.Item.Cells[3].ColumnSpan = 2; e.Item.Cells.RemoveAt(4); //The error above is thrown because of this } } Any help would be much appreciated!! Quote
Moderators Robby Posted January 14, 2004 Moderators Posted January 14, 2004 I suggest using a Datalist instead. Quote Visit...Bassic Software
samsmithnz Posted January 14, 2004 Posted January 14, 2004 I suggest using a Datalist instead. Why? Quote Thanks Sam http://www.samsmith.co.nz
g_r_a_robinson Posted January 14, 2004 Author Posted January 14, 2004 Yeah Why!! I know its possible, a datalist would'nt suit my needs since a lot of what I need to do is apply different sorts, button columns etc. Quote
Netnoobie Posted January 14, 2004 Posted January 14, 2004 A DataList lets you format the data in HTML and is quite flexible for displaying bindable data. The DataGrid is going to be too rigid for your needs it looks like. Quote
samsmithnz Posted January 14, 2004 Posted January 14, 2004 I'm very interested in this thread at the moment. I'm currently in a proof of concept stage for a internal ASP.NET application that displays invoices. We'd like to make the grid editable, maybe even a bit like SQL Server, where the bottom row is blank and you start typing in it to add another row. Eventually we'll be integrating with Biztalk 2004 and all this XML stuff, but whatr should I be using for this? Whats you recommendation? What ARE the differences between the Datagrid and the DataList? Are there others that are suitable for this sort of functionality? Quote Thanks Sam http://www.samsmith.co.nz
Moderators Robby Posted January 14, 2004 Moderators Posted January 14, 2004 For functionality and features the DataGrid is a better choice, but when it comes to displaying a datatable in a multi-row appearance then a DataList is a better choice. Don't get me wrong you can certainly accomplish this with a grid, but not as easily. The DataList is ideal for displaying something like this.... http://www.bassicsoftware.com/UsefulLinks.aspx Quote Visit...Bassic Software
dsigns Posted January 26, 2004 Posted January 26, 2004 Dont use a boundcolumn, you would use a templatecolumn instead. <Columns> <asp:TemplateColumn HeaderText="Information"> <ItemTemplate><%# Databinder.Eval(Container.DataItem,"Date")%> <%# Databinder.Eval(Container.DataItem,"ByWho")%> <%# Databinder.Eval(Container.DataItem,"FK_Action_Performed")%><br> <%# Databinder.Eval(Container.DataItem,"Note_Description")%> </ItemTemplate> </asp:TemplateColumn> </Columns> Quote
Moderators Robby Posted January 27, 2004 Moderators Posted January 27, 2004 dsigns, Binding executes faster than using the methods you posted above. If you're using a control that is not included in the datagrid/list than yes it makes sense, otherwise I cannot agree your method. Quote Visit...Bassic Software
dsigns Posted January 27, 2004 Posted January 27, 2004 I was under the impression he was looking for format his datagrid in the specific way he listed it above. If that's the case, then the way I stated will work. Quote
Moderators Robby Posted January 27, 2004 Moderators Posted January 27, 2004 As I said "If you're using a control that is not included in the datagrid/list than yes it makes sense". Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.