by Pieter Brinkman
30. January 2009 03:47
You can use a string array as datasource and view the string values by using the Container.DataItem property.
Code example
Codebehind:
string[] testData = {"1","two","3","4"};
rptDemo.DataSource = testData;
rptDemo.DataBind();
And in the .aspx:
<asp:Repeater runat="server" ID="rptDemo">
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</asp:Repeater>
by Pieter Brinkman
23. June 2008 08:46
I wrote an extension method for the string type. With this method you can check if an string is an Guid. The method returns a Bool.
public static class StringExtensions
{
public static bool IsGuid(this string input)
{
Regex isGuid = new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);
bool isValid = false;
if (input != null)
{
if (isGuid.IsMatch(input))
{
isValid = true;
}
}
return isValid;
}
}
If you're wondering I didn't wrote the Regex myself :-) (but it works)
This brute-force method is mutch faster (thanks to Arjan and Tag for the comments):
public static bool IsGuid(this string input)
{
try
{
new Guid(input);
return true;
}
catch (ArgumentNullException) {}
catch (FormatException) {}
catch (OverflowException) {}
return false;
}
A good example how extension methods can make some things easier.
Hope it helps!