<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Invalid Date" SetFocusOnError="true" OnServerValidate="CustomValidator_Date"> </asp:CustomValidator>

using System.Globalization;

protectedvoid CustomValidator_Date(object source, ServerValidateEventArgs args)
{
IFormatProvider culture = newCultureInfo("en-AU", true);
try
{
DateTime.ParseExact(args.Value, "d MMM yyyy", culture);
args.IsValid =
true;
}
catch
{
args.IsValid =
false;
}
}
 
Here's a sweet way to get the last inserted ID when using an SqlDataSource to do your insert.  First add ;SET @NewId = Scope_Identity() to the end of your InsertCommand, and to the InsertParameters add:

<
asp:Parameter Name="NewId" Type="Int32" Direction="Output"
/>

Then you can get the ID in the data source's Inserted event like this:

protected
void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
Int32 id = (Int32)e.Command.Parameters["@NewId"].Value;
}
 
SELECT CONVERT(varchar,c.DayDate,3) AS DayDate, b.BlockName, tc.StudyYearID, tc.ClassName, a.StudentID, COUNT(a.StudentID) AS Occurrences
FROM tblAttendance a
INNER JOIN tblCalendar c ON c.DateID=a.DateID
INNER JOIN tblBlocks b ON b.BlockID=a.BlockID
INNER JOIN tblTimetableClass tc ON tc.ClassID=a.ClassID
GROUP BY c.DayDate, b.BlockName, tc.StudyYearID, tc.ClassName, a.StudentID
HAVING COUNT(a.StudentID)>1
 
I was wondering how to make a LinkButton control open the page in a new window when I realised there's actually a control to do just that, the HyperLink control, that has a Target attribute.  The downside of this is you can't do any OnClick processing, so if you need to do that before openeing the page you'll have to use LinkButton and register a script with window.open javascript code in it.
 
Here's some sweet javascript to replace the items of a drop down list with a larger panel that can display more information and be formatted as desired.  In my case the text in the drop down was too long and I wanted to wrap it over several lines, so I created a popup layer positioned over the drop down list with links for the drop down items to set the selected value.

Place a div around your drop down list like this (it's was in a gridview, hince the IDfield to give the div a unique id):

<
div id='<%# Eval("IDfield") %>' onclick='ShowComments("<%# Eval("IDfield") %>")'>
</div>

Add a panel to show your items, like this:

<
asp:Panel ID="CommentPanel" runat="server" style="display:none; position:absolute; width:500px; top:300px; left:300px;">
<input type="hidden" id="dropID" />
<a href="#" onclick="CloseComments(); return false;" style="float:right; position:relative; left:-16px;background-color:White; margin-top:1px; padding-left:2px; padding-right:2px;" title="Close">X</a>
...List item links here with OnClientClick='HideComments(this)'...
</asp:Panel>

Then add this Javascript: 

<scripttype="text/javascript">
function ShowComments(param) {
var div = document.getElementById(param);
var panel = document.getElementById('<%= CommentPanel.ClientID %>');
panel.style.top = getY(div)-20 +
"px";
panel.style.left = getX(div)-40 +
"px";
panel.style.display =
"";
var hidden = document.getElementById("dropID");
var drop = div.getElementsByTagName("select")[0];
if (drop) {
hidden.value = drop.id;
drop.blur();
}
else {
hidden.value =
"";
}
}

function HideComments(link) {
var panel = document.getElementById('<%= CommentPanel.ClientID %>');
panel.style.display =
"none";
var hidden = document.getElementById("dropID");
if (hidden.value) {
var drop = document.getElementById(hidden.value);
for (i=0; i<drop.length; i++) {
if (drop.options[i].text == link.innerHTML) {
drop.selectedIndex = i; }
}
}
}

function CloseComments() {
var panel = document.getElementById('<%= CommentPanel.ClientID %>');
panel.style.display =
"none";
}

function getY( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue = iReturnValue + oElement.offsetTop;
oElement = oElement.offsetParent;
}
return iReturnValue;
}

function getX( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue = iReturnValue + oElement.offsetLeft;
oElement = oElement.offsetParent;
}
return iReturnValue;
}
</script>
 
When you have long text associated with radio button in an ASP.NET RadioButtonList the text wraps under the radio button, rather than staying in line with the text on the first line.  To get it to wrap properly add CssClass="radiowrap" to the RadioButtonList control, with the CSS:

table.radiowrap
input { float: left; }
table.radiowrap label { margin-left: 22px; display: block; }
 
DataTable dt = newDataTable();
dt.Columns.Add(
"ID", typeof(Int32));
dt.Columns.Add(
"SEQ", typeof(Int32));
dt.Rows.Add(
new object[] { 1, 1 });
dt.Rows.Add(
new object[] { 2, 3 });
dt.Rows.Add(
new object[] { 3, 2 });
DataView dv = dt.DefaultView;
dv.Sort =
"SEQ";
Repeater1.DataSource = dv;
Repeater1.DataBind();
 
DELETE a FROM table1 a
INNER JOIN table2 b ON b.SomeID=a.SomeID
WHERE b.SomeField=@SomeFieldValue
 
In IE the report viewer control cuts off the bottom of the report, including the horizontal scroll bar, and if you have parameters at the top possibly some of your data too.  To make it show the whole report and the horizontal scroll bar add style="margin-bottom:50px;" to the report viewer control.

Update 12/03/2010: Actually there is a bug with the report viewer control in IE8 that sometimes prevents horizontal scrolling going right accross the report.  There are some suggestions to add display:table to the report viewer which does make the horizontal scrolling work but can break the height.  The only real fix is to remove the doctype to put the brwser in quirks mode, but is not really desirable, especially if you have the doctype in a master page and want it on your other pages.  So in the end I found the best way to get it to display right accross all browsers is to put the report viewer control in a seperate file with no doctype and include that in an iframe, then you can forget about all the margin and display styles.
 
You can make columns in an SQL Server Reporting Services report sortable, which adds little up and down arrows next to the column header.  To do this, when editing the report in Visual Studio go to the Layout view and right click the table header cell and choose Properties.  Go to the Interactive Sort tab, check Add and interactive sort action to this textbox, and select a sort expression, usually Fields!FieldName.Value.  Do this for each column you want to be sortable, preview it to test and sort until your heart's content.