Many times I wantDreamweaverCan you support methods in the class you write? Because it is really strong in fast development, but many detailed functions cannot be implemented. For example, I want to process the specified string, frequently used is the display of the news topic list on the homepage of the website. The length of each line is greater"..."Display. In general sense, you can add this method to the desired page. However, if there are many such pages, paste this method once for each page, if there is any modification, it is even more troublesome. This is also contrary to the object-oriented principle, so I thought of encapsulating the methods commonly used in website development into a class and then introducing this namespace into the corresponding page. Below I will give someCodeExample
FirstVs2003CreateClassThe project is as follows:
Using system;
Using system. Data;
Using system. Data. sqlclient;
Using system. configuration;
Namespace aspnetx
{
/// <Summary>
/// Summary description for aspnetx.
///This class mainly defines some common business logic for website development
///This can simplify website project development and save a lot of coding time.
/// </Summary>
Public class aspnetx
{
......
......
......
/// <Summary>
///Generated according to the specified lengthArticleQuestion
///Move the mouse to display the full name.
/// </Summary>
/// <Param name = "str">String to be processed</Param>
/// <Param name = "length">Article Length</Param>
/// <Returns> </returns>
Public static string titlestring (string STR, int length)
{
Int I = 0, j = 0;
STR = Str. Trim ();
String str_s = STR;//The passed string, used when the full name is displayed
Foreach (char CHR in Str)
{
If (INT) CHR> 127)
{
I + = 2;
}
Else
{
I ++;
}
If (I> length)
{
STR = Str. substring (0, j) + "......";
Break;
}
J ++;
}
//Join thisHtmlThe Code moves the mouse to display the full name
STR = "<font Title = '" + str_s + "'>" + STR + "</font> ";
Return STR;
}
}
}
CompileBinDirectoryAspnetx. dllDifferent projects may generate differentDLL
Copy to the website directoryBinFolder, then open the page to be introduced, and add
<% @ Import namespace = "aspnetx" %>
You can modify the reference method based on your compilation. For example:
<% # Aspnetx. titlestring (dataset1.fieldvalue ("newstitle", container), 40) %>
I think this method is good for small projects. You can add some other methods to it.