// Generated by reflector from E: \ codeserver \ dll \ CFSNS. commontools. dll
Namespace CFSNS. Common. Tools. webcontrolextension
{
Using CFSNS. Common. tools;
Using CFSNS. Common. Tools. enumextension;
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. runtime. compilerservices;
Using system. runtime. interopservices;
Using system. text;
Using system. Text. regularexpressions;
Using system. Web. UI. webcontrols;
Public static class webcontrolextension
{
Public static void bindselected (this checkboxlist CB, string selectedstring, string seperator = @ "\ | ")
{
String [] strarray = RegEx. Split (selectedstring, seperator );
For (INT I = 0; I <CB. Items. Count; I ++)
{
For (Int J = 0; j <strarray. length; j ++)
{
If (CB. items [I]. value = strarray [J])
{
CB. items [I]. Selected = true;
}
}
}
}
Public static void databindp (this listcontrol control, string firstlinename = "Select...", string value = "")
{
Control. databind ();
If (! String. isnullorempty (firstlinename ))
{
Control. Items. insert (0, new listitem (firstlinename, value ));
}
}
Public static void databindp (this listcontrol control, indexinfo tobindinfo, string firstlinename = NULL, string firstlinevalue = "", string datatextformatstring = NULL)
{
Control. datasource = tobindinfo;
Control. datatextfield = "Infos ";
Control. datavaluefield = "name ";
Control. datatextformatstring = datatextformatstring;
Control. databind ();
If (! String. isnullorempty (firstlinename ))
{
Control. Items. insert (0, new listitem (firstlinename, firstlinevalue ));
}
}
Public static void databindp (this Repeater control, type, string firstlinename = NULL, string firstlinevalue = "", databindoptions option = 0)
{
Func <keyvaluepair <string, string>, string> keyselector = NULL;
Dictionary <string, string> first = new dictionary <string, string> ();
If (! String. isnullorempty (firstlinename ))
{
First [firstlinevalue] = firstlinename;
}
Iorderedenumerable <keyvaluepair <string, string> second = from P in type. getenumdescriptions ()
Orderby (INT) enum. parse (type, P. Key). tostring ()
Select P;
If (option = databindoptions. Text)
{
Control. datasource = first. Concat <keyvaluepair <string, string> (second );
}
Else if (option = databindoptions. value)
{
If (keyselector = NULL)
{
Keyselector = P => (INT) enum. parse (type, P. Key). tostring ();
}
Control. datasource = first. concat <keyvaluepair <string, string> (second ). todictionary <keyvaluepair <string, string>, string> (keyselector, P => P. value );
}
Else
{
Control. datasource = first. concat <keyvaluepair <string, string> (second ). todictionary <keyvaluepair <string, string>, string> (P => P. value, P => P. value );
}
Control. databind ();
}
Public static void databindp (this listcontrol control, type, string firstlinename = NULL, string firstlinevalue = "", string datatextformatstring = NULL, databindoptions option = 0)
{
Func <keyvaluepair <string, string>, string> keyselector = NULL;
Func <keyvaluepair <string, string>, string> func2 = NULL;
Func <keyvaluepair <string, string>, string> func3 = NULL;
Control. datatextfield = "value ";
Control. datavaluefield = "key ";
Control. datatextformatstring = datatextformatstring;
If (option = databindoptions. Text)
{
If (keyselector = NULL)
{
Keyselector = P => (INT) enum. parse (type, P. Key). tostring ();
}
Control. datasource = type. getenumdescriptions (). orderby <keyvaluepair <string, string>, string> (keyselector );
}
Else if (option = databindoptions. value)
{
If (func2 = NULL)
{
Func2 = P => (INT) enum. parse (type, P. Key). tostring ();
}
Control. datasource = from P in type. getenumdescriptions (). todictionary <keyvaluepair <string, string>, string> (func2, P => P. value)
Orderby P. Key
Select P;
}
Else
{
If (func3 = NULL)
{
Func3 = P => (INT) enum. parse (type, P. Key). tostring ();
}
Control. datasource = type. getenumdescriptions (). orderby <keyvaluepair <string, string>, string> (func3 ). todictionary <keyvaluepair <string, string>, string> (P => P. value, P => P. value );
}
Control. databind ();
If (! String. isnullorempty (firstlinename ))
{
Control. Items. insert (0, new listitem (firstlinename, firstlinevalue ));
}
}
Public static string selectedtexts (this checkboxlist, string seperator = ",")
{
Stringbuilder builder = new stringbuilder ();
Foreach (listitem item in checkboxlist. Items)
{
If (item. Selected)
{
Builder. append (item. Text );
Builder. append (",");
}
}
Int length = builder. length;
Return (length> 0 )? Builder. Remove (length-1, 1). tostring (): String. Empty );
}
Public static t selectedvalues <t> (this checkboxlist, t defaultvalue = NULL) where T: struct
{
Object obj2 = 0;
For (INT I = 0; I <checkboxlist. Items. Count; I ++)
{
If (checkboxlist. items [I]. Selected)
{
Obj2 = (INT) obj2) | convert. toint32 (checkboxlist. items [I]. value. toenum <t> (defaultvalue ));
}
}
If (! Obj2.equals (0 ))
{
Return (t) obj2;
}
Return defaultvalue;
}
Public static string selectedvalues (this checkboxlist, string seperator = "| ")
{
Stringbuilder builder = new stringbuilder ();
For (INT I = 0; I <checkboxlist. Items. Count; I ++)
{
If (checkboxlist. items [I]. Selected)
{
Builder. append (checkboxlist. items [I]. Value + seperator );
}
}
If (builder. length> 0)
{
Builder. Remove (builder. Length-seperator. length, seperator. Length );
}
Return builder. tostring ();
}
Public Enum databindoptions
{
Text,
Value,
Description
}
}
}