If you need to convert a date that is in a string format:
03/18/13
into a SQL Server Date so that you can process it, ORDER BY, etc.. then do the following:
CAST(HIRE as Datetime)
where HIRE is a date in string format. If you want to display the date in a particular format, then just CONVERT it to the format you want:
CONVERT(CHAR(10),CAST(HIRE as Datetime),101) as Hire_Date
The CHAR(10) saves space for 10 characters and the 101 is one of the formats available. I didn't use VARCHAR because the field is exactly 10 characters. See the link below for a format you want to use if you don't like the 101 format (mm/dd/yyyy)
http://msdn.microsoft.com/en-us/library/ms187928.aspx
Monday, March 18, 2013
Sunday, August 26, 2012
Using a Dropdown with Yes No instead of 1 or 0 in a GridView
| Showing Yes or No instead of 1 or 0 in GridView |
You don't have to have another sqldatasource to bind a yes or a no. Try this solution and let me know if this works for you.
<asp:TemplateField HeaderText="YOUR_FIELD" SortExpression="YOUR_FIELD">
<EditItemTemplate>
<asp:DropDownList ID="dropYesNo" runat="server" SelectedValue='<%# Bind("YOUR_FIELD") %>' >
<asp:ListItem Value="0">No</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<%#Eval("YOUR_FIELD").ToString() == "1" ? "Yes" : "No" %>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
Of course, the field that you want needs to be converted to a TEMPLATE FIELD. Let me know if you don't know how to do that and I'll help or post how to.
| Yes or No binds from DropDown |
I use
<%#Eval("YOUR_FIELD").ToString() == "1" ? "Yes" : "No" %>
the EVAL to test if the field is 1 or 0 to show Yes or No in the gridview. I put this in the ItemTemplate.
Also notice,
<asp:ListItem Value="0">No</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
So that your 0 and 1 are written back to your table when you click update.
Happy Coding... :)
Friday, April 13, 2012
YouTube Video Has Green Background
| YouTube Green Screen |
If you play a video on YouTube and all you see is a green screen background but you can hear the audio then you may be able to solve the problem by right-clicking on the video. The Adobe Flash Player Settings will appear on the screen. Click on the 1st icon at the bottom that looks like a monitor (Display), then UN-CHECK the option that says, "Enable hardware acceleration"
Subscribe to:
Posts (Atom)