I currently have a GridView that pulls information from a SQL database. My code to do this is at the bottom.
Now what I am TRYING to do is make certain columns not pull from the database but calculate on the fly.
If you can help me with one example I can figure out the rest.
The example I need would be:
DateIn pulls from database.
DateOut pulls from database.
I need to calculate the difference between the two and put it in a column.
I would LIKE to be able to do this using strings if possible (and some conversion) because if I store the dates in SQL as a date/time it attaches 12:00:00am to all my fields - so I'd store as a string and have the user type 10/10/2008.
Hopefully this was clear if not I'll try to say in another way.
I need to store two dates in a database, pull this into a datagrid and get the difference in dates on-the-fly so that I can populate another column of the datagrid.
Thanks!
ASP.Net Page:
CODE
<asp:GridView ID="inout_DataGrid" runat="server" AutoGenerateColumns="False" CellPadding="3"
Font-Names="Verdana" Font-Size="X-Small" ForeColor="Black" PageSize="5" Width="902px">
<Columns>
<asp:BoundField DataField="Quarter" HeaderText="Quarter" SortExpression="Quarter">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="75px" />
<HeaderStyle Font-Bold="True" ForeColor="Black" VerticalAlign="Top" />
</asp:BoundField>
<asp:BoundField DataField="InDate" HeaderText="In">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="75px" />
<HeaderStyle Font-Bold="True" ForeColor="Black" VerticalAlign="Top" />
</asp:BoundField>
<asp:BoundField DataField="OutDate" HeaderText="Out">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="75px" />
<HeaderStyle Font-Bold="True" ForeColor="Black" VerticalAlign="Top" />
</asp:BoundField>
<asp:BoundField DataField="Days_Since_In" HeaderText="Days Since In">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="100px" />
<HeaderStyle Font-Bold="True" ForeColor="Black" VerticalAlign="Top" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl_Days_To_Issue" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"InDate") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Days_To_Issue" HeaderText="Days To Issue">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="100px" />
<HeaderStyle Font-Bold="True" ForeColor="Black" VerticalAlign="Top" />
</asp:BoundField>
<asp:BoundField DataField="RFD_Sent_Date" HeaderText="RFD Sent Date">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="100px" />
<HeaderStyle Font-Bold="True" ForeColor="Black" VerticalAlign="Top" />
</asp:BoundField>
<asp:BoundField DataField="Days_Until_RFD" HeaderText="Days Until RFD Sent">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="100px" />
<HeaderStyle Font-Bold="True" ForeColor="Black" VerticalAlign="Top" />
</asp:BoundField>
<asp:BoundField DataField="Team" HeaderText="Team" SortExpression="Team">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="100px" />
<HeaderStyle Font-Bold="True" ForeColor="Black" VerticalAlign="Top" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Time" HeaderText="Time Spent">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="100px" />
<HeaderStyle Font-Bold="True" ForeColor="Black" VerticalAlign="Top" Wrap="False" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="Button3" runat="server" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"ID")%>'
CommandName="update" ImageUrl="images/edit2.jpg" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle ForeColor="Black" Wrap="False" />
<HeaderStyle BackColor="#B7DBFF" Font-Bold="True" ForeColor="Black" VerticalAlign="Top"
Wrap="False" />
<AlternatingRowStyle BackColor="#DBEDFF" />
</asp:GridView>
My VB.NET page:
CODE
'Begin Fill In/Outs Data Grid
Dim SQLCommand As SqlDataAdapter
Dim dataset_report As DataSet
SQLCommand = New SqlDataAdapter("SELECT * FROM InOuts", db_connection)
dataset_report = New DataSet()
SQLCommand.Fill(dataset_report, "InOuts")
inout_DataGrid.DataSource = dataset_report.Tables("InOuts").DefaultView
inout_DataGrid.DataBind()
'End Fill In/Outs Data Grid