The manual webpart deployment method described in Note 1 is troublesome, and the visual interface cannot be seen during the development of webpart. it is inconvenient to set style attributes and debug them, this document uses the "user control" to replace webpart.
We also continued the previous example, which was implemented using "User Control" this time.
1. Create an ASP. NET web application in the solutionProgramName simpleascx
2. Create a "Web user control" page named ascxgrid. ascx
3. Drag a gridview and set properties.
Ascx page:
<% @ Control Language = "C #" autoeventwireup = "true" codebehind = "ascxgrid. ascx. CS "inherits =" simpleascx. ascxgrid "%> <asp: gridview id =" gridview1 "runat =" server ">
CSCode:
Using system; using system. collections; using system. configuration; using system. data; using system. web; using system. web. security; using system. web. ui; using system. web. UI. htmlcontrols; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; namespace simpleascx {public partial class ascxgrid: system. web. UI. usercontrol {protected void page_load (Object sender, eventargs e) {datatable dt = getdatatable (); gridview1.datasource = DT; gridview1.databind ();} private datatable getdatatable () {datatable dt = new datatable (); DT. columns. add ("ID"); DT. columns. add ("name"); DT. columns. add ("date"); For (INT I = 0; I <20; I ++) {datarow DR = DT. newrow (); Dr [0] = I; Dr [1] = "colname1" + ":" + I; Dr [2] = "create Date:" + datetime. now; DT. rows. add (DR) ;}return DT ;}}}
4. regenerate,
Copy the simpleascx. dll file in the bin directory to the C: \ Inetpub \ wwwroot \ WSS \ virtualdirectories \ 80 \ bin directory.
Copy the ascxgrid. ascx file to the C: \ Inetpub \ wwwroot \ WSS \ virtualdirectories \ 80 \ wpresources directory.
OK. So far, the ascx user control has been created. Configure quickpart below
Same as deploying a webpart control:
1. Add quickpart. DLL to the C: \ Inetpub \ wwwroot \ WSS \ virtualdirectories \ 80 \ bin directory;
2. Set the Web. config of the website set, and add the following configuration section in configuration-> SharePoint-> safecontrols.
<Safecontrol Assembly = "quickpart, version = 1.0.0.0, culture = neutral, publickeytoken = 2d0bb71b2dd16f9e" namespace = "Microsoft. PRC. SharePoint" typename = "*" Safe = "true"/>
3. In configuration-> system. Web, find the trust configuration section to increase the trust level and change wss_minimal to full.
4. Import webpart
Go to the WSS site and choose website operations> website Settings> Web components"
Import Microsoft. PRC. Sharepoint. consumerquickpart and Microsoft. PRC. Sharepoint. providerquickpart to the Web Part Library.
5. Create a test page, quickparttest;
6. Add providerquickpart on the test page;
7. Edit the webpart. In the attribute bar on the right, you can view the created ascxgrid user control. After selecting the control, you can complete the selection.
Compared with the development and deployment of webpart, it is much more convenient and error-prone.
Vengen
2011-01-04