supersnoop Posted December 17, 2003 Posted December 17, 2003 Hi Guys / Girls, I've got a deadline tommorrow and I"m stuck. I've got a datagrid wired up perfectly to a datatable. However, I need an extra column for calculations. I can't seem to add it. If I add it on the resport.aspx page then it shows but I can't add data. But if I try and add the column to the datatable (see below) at runtime then it doesn't show. What am I doing wrong. Please can someone show me how to add a column to a datatable at runtime and have it show up? Thx. I"ll owe you one. ---------------------------------------------- report.aspx: <ASP:Datagrid AutoGenerateColumns="false" OnItemDataBound="CalcTotal" ShowFooter="True" id="grdQueryResults" runat="server" BorderColor="black" BorderWidth="1" GridLines="Both" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" width="200"> <Columns> <ASP:BoundColumn DataFormatString="{0:d}" HeaderText="Start Date" DataField="datStartDate"></ASP:BoundColumn> <ASP:BoundColumn DataFormatString="{0:d}" HeaderText="End Date" DataField="datEndDate"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Number of Contacts Registered in CIMA" DataField="intInterestTotal"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Application Completed" DataField="intAppCompleted"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Cancelled" DataField="intAppCancelled"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Ready For Review" DataField="intAppReadyForReview"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Review Completed" DataField="intAppReviewComplete"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Held" DataField="intAppHeld"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Deferred" DataField="intDeferred"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Rejected" DataField="intRejected"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Offer Sent" DataField="intOfferSent"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Offer Declined" DataField="intOfferDeclined"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Wait List" DataField="intWaitlist"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Offer Accepted" DataField="intOfferAccepted"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Conditional Acceptance" DataField="intConditionalAcceptance"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Total Applicants" DataField="intTotalApplicants"></ASP:BoundColumn> <ASP:BoundColumn HeaderText="Learners Enrolled" DataField="intLearnersEnrolled"></ASP:BoundColumn> </Columns> </ASP:Datagrid> ------------------------------------------------------- report.aspx.vb 'create datatable Dim dt As New DataTable() Dim da As New SqlDataAdapter() da.SelectCommand = cmd da.Fill(dt) 'create datacolumn Dim dcPercentage1 As New DataColumn("Percentage of Applicants from Contacts", GetType(Integer)) dcPercentage1.Expression = "((12 / 6) * 100)" dt.Columns.Add("dcPercentage1", GetType(Integer)) ' Associate the data grid with the data Me.grdQueryResults.DataSource = dt Me.grdQueryResults.DataBind() cnn.Close() Quote
Moderators Robby Posted December 17, 2003 Moderators Posted December 17, 2003 I think you would need to loop through the Datatable and add a new row for each existing row then add it to the column. Quote Visit...Bassic Software
supersnoop Posted December 17, 2003 Author Posted December 17, 2003 Got it! autocreatcolumns = true !!! and don't make column heading on aspx.vb page a "string" ' cause it aint. Thanks anyway..... Quote
Moderators Robby Posted December 17, 2003 Moderators Posted December 17, 2003 good stuff, I didn't think of AutoGenerateColumns. 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.