Lag luam Scenario:
Thoob plaws Enterprise teg NTXHUAB rau cov tuam txhab raug nrog 30+ cov chaw thiab ob peb neeg huv dozen.
Cov hom phiaj ua lag ua luam:
Txawm ib tug tibneeg ntau ntau uas ua hauj lwm pab pawg (saib xyuas, qhov chaw, yam), tej ntaub ntawv yuav tsum raug tswj tseg rau ntiaj teb no npaum li. Piv txwv, npaj sau ntaub ntawv pov rau txhua qhov chaw ntawm lub tuam txhab (e.g. raug cov vaj tse, cov chaw zov me nyuam warehouse, chaw muag) yuav tsum tau tswj nyob rau hauv ib qho chaw central.
Kev teeb meem:
Tus enterprise taxonomy yog DVR siv ntau qhov chaw collections. Peb yuav tau nyiam tsim ntaub ntawv pov lub npe ntawm qhov chaw khiav hauj lwm rau lub cev nyob rau hauv kev cai WSS sau. Ces, Thaum peb yuav tsum tau muaj ib kem nyob rau hauv ib chav ntawv kawm yam (los yog ib sab ntxiv rau lub tsev qiv ntawv sau lossis doc) uas muaj nyob tej qhov chaw neeg, peb yuav tsim ib sab siv "lookup cov" datatype thiab taw tes rau daim ntawv npaj.
Hmoov tsis, lookup datatypes no yuav tsum tau nkag los sau "Senior" lub ntsiab lus tias peb kev sau ntaub ntawv pov tsis tau saib ntsoov txog qhov chaw collections.
Kev tov:
Siv hom kev cai ntaub ntawv tshiab DVR raws li SPField thiab cov uas muaj tuaj raws li tus DropDownList hauv lub zog ListItems populate los npaj WSS daim ntawv povhwm poob haujlwm no.
Peb tsim ib tshiab ntawm phau hu ua "http://localhost/EnterpriseData". Muaj, peb tsim tau ib daim ntawv teev kev cai hu ua "Neeg chaw". Daim ntawv cia li siv tus txheem "Title" teb kom muaj daim ntawv ntawm qhov chaw neeg sij.
Ib qho raws li discrete ntau qhov mus tsim ib lub hom kev cai ntaub ntawv nyob rau hauv WSS. Lawv yuav:
- Txhais tau ib chav kawm uas inherits ntawm SPField (ib tug yuav inherit los ntawm lwm tus tswv num yog yuav tsum tau).
Ntawm no yog cov chaws rau cov uas:
pej xeem hoob XYZZYCorporateLocationField : SPFieldText
{
pej xeem XYZZYCorporateLocationField
(SPFieldCollection liaj teb, hlua typeName, hlua displayName)
: puag(liaj teb, typeName, displayName) { }
pej xeem XYZZYCorporateLocationField
(SPFieldCollection liaj teb, hlua displayName)
: puag(liaj teb, displayName) { }
pej xeem override BaseFieldControl FieldRenderingControl
{
txais
{
BaseFieldControl tswj = tshiab XYZZYCorporateLocationFieldControl();
hwj xwm. FieldName = qhov no.InternalName;
rov qab los tswj;
} //txais
} // fieldrenderingcontrol
pej xeem override hlua GetValidatedString(nruas tus nqi)
{
Yog hais tias (qhov no.Yuav tsum tau || tus nqi. ToString().Qhov sib npaug(Txoj hlua.Npliag))
{
pov tshiab SPFieldValidationException ("Department yuav tsis raug ua hauj lwm.");
}
rov qab los puag.GetValidatedString(tus nqi);
} // getvalidatedstring
} // XYZZYCorporateLocation
- Txhais tau lwm cov hoob uas inherits los ntawm cov tswv teb tswj, raws li nyob rau hauv:
pej xeem hoob XYZZYCorporateLocationFieldControl : BaseFieldControl
{
kev tiv thaiv DropDownList XYZZYCorporateLocationSelector;
kev tiv thaiv override hlua DefaultTemplateName
{
txais
{
rov qab los "XYZZYCorporateLocationFieldControl";
}
} // DefaultTemplateName
pej xeem override nruas Tus nqi
{
txais
{
EnsureChildControls();
rov qab los qhov no.XYZZYCorporateLocationSelector.SelectedValue;
} // txais
teem caij
{
EnsureChildControls();
qhov no.XYZZYCorporateLocationSelector.SelectedValue = (hlua)qhov no.ItemFieldValue;
} // teem caij
} // override tus nqi kwv
kev tiv thaiv override khoob lug CreateChildControls()
{
Yog hais tias (qhov no.Teb == null || qhov no.ControlMode == SPControlMode.Zaub)
rov qab los;
puag.CreateChildControls();
qhov no.XYZZYCorporateLocationSelector =
(DropDownList)TemplateContainer.FindControl("XYZZYCorporateLocationSelector");
Yog hais tias (qhov no.XYZZYCorporateLocationSelector == null)
pov tshiab Kos("KEV UA YUAM KEV: Tsis tau thauj khoom. Cov ntaub ntawv ASCX!");
Yog hais tias (!qhov no.Phab IsPostBack.)
{
siv (SPSite kawm ntawv = tshiab SPSite("http://localhost/enterprisedata"))
{
siv (SPWeb Web = kawm ntawv. OpenWeb())
{
Splist.Update() currentList = web. Teev["Neeg qhov chaw"];
foreach (SPItem XYZZYCorporateLocation nyob rau hauv currentList.Items)
{
Yog hais tias (XYZZYCorporateLocation["Title"] == null) ntxiv mus;
hlua theTitle;
theTitle = XYZZYCorporateLocation["Title"].ToString();
qhov no.XYZZYCorporateLocationSelector.Items.Add
(tshiab ListItem(theTitle, theTitle));
} // foreach
} // siv lub web spweb = site.openweb()
} // siv qhov chaw spsite = spsite tshiab("http://localhost/enterprisedata")
} // nws tsis yog ib tug postback
} // CreateChildControls
} // XYZZYCorporateLocationFieldControl
Cov cai saum toj no yeej implements lub logic rau populating tus DropDownList uas qhov tseem ceeb ntawm cov WSS kev cai sau nyob hauv http://localhost/enterprisedata thiab raug teev hais "neeg huv".
Kuv txhais ob hoob nyob hauv ib tus neeg ua ntaub ntawv thov tib .cs, compiled nws thiab muab tso rau hauv lub GAC (strong yuav tsum, tau mas).
-
Siv ib txoj kev los tswj template (.ascx) li:
<%@ Tswj Hais lus= "C#" Inherits="Microsoft.SharePoint.portal.ServerAdmin.CreateSiteCollectionPanel1,Microsoft.SharePoint.portal,Version = 12.0.0.0, Culture = nruab nrab,PublicKeyToken = 71e9bce111e9429c" compilationMode= "Ib txwm" %>
<%@ Rau npe Tagprefix= "wssawc" Namespace="Microsoft.SharePoint.WebControls" Sib dhos="Microsoft.SharePoint, Version = 12.0.0.0, Culture = nruab nrab, PublicKeyToken = 71e9bce111e9429c" %> <%@ Rau npe Tagprefix= "SharePoint" Namespace="Microsoft.SharePoint.WebControls" Sib dhos="Microsoft.SharePoint, Version = 12.0.0.0, Culture = nruab nrab, PublicKeyToken = 71e9bce111e9429c" %>
<SharePoint:RenderingTemplate ID= "XYZZYCorporateLocationFieldControl" runat= "neeg rau zaub mov">
<Template>
<asp:DropDownList ID= "XYZZYCorporateLocationSelector" runat= "neeg rau zaub mov" />
</Template>
</SharePoint:RenderingTemplate>
Cov hais los saum toj no rua hauv c:\qhov kev pab cuam filescommon filesmicrosoft sharedweb neeg rau zaub mov extensions12controltemplates.
- Thaum kawg, tsim ntaub ntawv XML mus kaw rau hauv peb cov... 12XML directory. No yog cov nyiaj thiab lub sij muaj peb cov hom ntaub ntawv rau kev cai CAML thiab rau kuv piv txwv, zoo li no:
<?xml Version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Teb Lub npe="TypeName">CorporateLocations</Teb>
<Teb Lub npe="ParentType">Ntawv nyeem</Teb>
<Teb Lub npe="TypeDisplayName">Qhov chaw neeg</Teb>
<Teb Lub npe="TypeShortDescription">Txhua XYZZY neeg qhov chaw xws li manufacturing los yog lwm lub chaw.</Teb>
<Teb Lub npe="UserCreatable">MUAJ TSEEB</Teb>
<Teb Lub npe="ShowInListCreate">MUAJ TSEEB</Teb>
<Teb Lub npe="ShowInDocumentLibraryCreate">MUAJ TSEEB</Teb>
<Teb Lub npe="ShowInSurveyCreate">MUAJ TSEEB</Teb>
<Teb Lub npe="ShowInColumnTemplateCreate">MUAJ TSEEB</Teb>
<Teb Lub npe="FieldTypeClass">Conchango.XYZZYCorporateLocationField, XYZZYCorporateLocationField, Version = 1.0.0.0, Culture = nruab nrab, PublicKeyToken = b0b19e85410990c4</Teb>
<RenderPattern Lub npe="DisplayPattern">
<Mus>
<Expr>
<Kem />
</Expr>
<Rooj plaub no Tus nqi=""/>
<Neej ntawd>
<HTML>
<![CDATA[<ntsua kev style = "xim:Liab"><b>]]>
</HTML>
<Kem SubColumnNumber="0" HTMLEncode="MUAJ TSEEB"/>
<HTML><![CDATA[</b></ntsua kev>]]></HTML>
</Neej ntawd>
</Mus>
</RenderPattern>
</FieldType>
</FieldTypes>
Tej ntaub ntawv no XML ntxiv seb yam ntaub ntawv rau kev cai WSS "qiv" thiab ntais ntawv up against lub GAC tau los ua ke.
Tom qab koj tsiv rau tag nrho cov khoom rau hauv qhov chaw, iisreset rau tus neeg rau zaub mov thiab nws yuav tsum tau tag nrho cov pib ua hauj lwm nicely.
siv System.Web.UI;
siv System.Web.UI.WebControls;
Kuv sim kom muaj kev koj yuav tshuaj. Tab sis kuv txuag, txhob siv DropDownList, Kuv tsuas muaj kev rau ib DropDownChoiceList. Koj sim kom paub ntxiv khoom rau ib DropDownChoiceList? Peb siv cov SharePoint 2007 SP1 thiab siv qhov muag saib lub Studio 2005 SP1.