Prepare for the publisher! (Applicable to DotNetNuke Version 4.3.1 or higher) using VB. NET or C #
This tutorial shows you how to create a DotNetNuke module using the DAL + "ExecuteSQL" method. DAL + is an extension of the DotNetNuke Data Access Layer (DAL.
Procedure
1. Install Visual Studio Express (click to download)
2. Install SQL Server Express (click to download)
3. Use one of the following methods to install DotNetNuke and create a DotNetNuke website
L Setting-up the Development Environment (using IIS)
L Setting-up the Development Environment (without IIS)
4. in Visual Studio, select "Build Solution" under "Build". If compilation succeeds, we can proceed to the next step.
Is the development environment ready?
You must have a website named DotNetNuke 4 that is ready for running. If you do not do this, you can use this link to seek help.
DotNetNuke is constantly updated, so the DotNetNuke forum is the best place to find the latest help and information.
I am very sorry that I cannot provide separate technical support for website setup, but I will help you with questions related to this tutorial.
Create a module
Create a module in two steps:
- Create a view Control
- Register this module in DotNetNuke
Create a Module Directory
Open your DotNetNuke website in Visual Studio
Create a View Control
Right-click the "topics topmodules" directory and choose "New Folder"
The new directory is named"SuperSimple"
Right-click the "SuperSimple" directory and choose "Add New Item ..."
Click"Add New Item"A dialog box is displayed:
Click "under" Visual Studio Installed Templates"Web User Control"
- In"Name"Enter later"SuperSimple. ascx"
- Make sure"Place code in a separate file"Selected
- Click"Add"Buttons
A "SuperSimple. ascx" file is created in the "SuperSimple" directory under the "topics topmodules" directory.
Click the plus sign next to the file to display the associated code behind file"SuperSimple. ascx. vb"(Or"SuperSimple. ascx. cs").
Double-click"SuperSimple. ascx"File, which will be opened in the main editing window. At this time, the page is still blank.
Click"Source"Press the button to switch to the source code view.
Enter the following code:
VB:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="SuperSimple.ascx.vb"
Inherits="DesktopModules_SuperSimple_SuperSimple" %>
Search:
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Button" /><br />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
C #:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SuperSimple.ascx.cs"
Inherits="DesktopModules_SuperSimple_SuperSimple" %>
Search:
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Button" OnClick="btnSearch_Click" /><br />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
Click"Design"Button conversion to design view
Double-click"SuperSimple. ascx. vb"(Or"SuperSimple. ascx. cs")
Replace the code in with the following code:
VB:
Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Security.PortalSecurity
Partial Class DesktopModules_SuperSimple_SuperSimple
Inherits Entities.Modules.PortalModuleBase
Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
ShowData("")
End If
End Sub
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
ShowData(txtSearch.Text)
End Sub
Private Sub ShowData(ByVal SearchString As String)
Dim mySqlString As New StringBuilder()
mySqlString.Append("SELECT FriendlyName, Description ")
mySqlString.Append("FROM {databaseOwner}{objectQualifier}DesktopModules ")
mySqlString.Append("WHERE Description like '%' + @SearchString + '%' ")
mySqlString.Append("ORDER BY FriendlyName")
Dim myParam As SqlParameter = New SqlParameter("@SearchString", SqlDbType.VarChar, 150)
myParam.Value = SearchString
Me.GridView1.DataSource = CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), myParam), IDataReader)
Me.GridView1.DataBind()
End Sub
End Class
C #:
using DotNetNuke;
using System.Web.UI;
using System.Text;
using System.Collections.Generic;
using System.Reflection;
using DotNetNuke.Security;
using System.Data.SqlClient;
using System.Data;
using DotNetNuke.Data;
partial class DesktopModules_SuperSimple_SuperSimple : DotNetNuke.Entities.Modules.PortalModuleBase
{
protected void Page_Load(object sender, System.EventArgs e) {
if (!Page.IsPostBack)
{
ShowData("");
}
}
protected void btnSearch_Click(object sender, System.EventArgs e) {
ShowData(txtSearch.Text);
}
private void ShowData(string SearchString) {
StringBuilder mySqlString = new StringBuilder();
mySqlString.Append("SELECT FriendlyName, Description ");
mySqlString.Append("FROM {databaseOwner}{objectQualifier}DesktopModules ");
mySqlString.Append("WHERE Description like \'%\' + @SearchString + \'%\' ");
mySqlString.Append("ORDER BY FriendlyName");
SqlParameter myParam = new SqlParameter("@SearchString", SqlDbType.VarChar, 150);
myParam.Value = SearchString;
this.GridView1.DataSource = ((IDataReader)(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), myParam)));
this.GridView1.DataBind();
}
}
SlaveBUILDSelect"Build Page".
The page should be compiled
Register the module in DotNetNuke
Use"Host"Log on to your DotNetNuke site and select"Host"Then select"Module Definitions".
Click the down arrow in the upper left corner and select"Create New Module".
InEdit Module DefinitionsMenu:
- InMODULE NAMEEnter "SuperSimple"
- InFOLDER TITLEEnter "SuperSimple"
- InFRIENDLY TITLEEnter "SuperSimple"
- InDESCRIPTIONEnter "SuperSimple"
- InVERSIONEnter 1.0"
Then clickUPDATE
InNEW DEFINITIONEnter "SuperSimple"
Then click"Add"
Then click"Add Control"
InEdit Module ControlMenu:
- InTITLEEnter "SuperSimple"
- InSOURCEFrom the drop-down list, select"Topmodule/SuperSimple. ascx"
- InTYPEFrom the drop-down list, select"View"
Then clickUPDATE
Click ADD in the page functions menu in the upper left corner of the website.
InPAGE MANAGEMENTMenuPAGE DETAILSIn:
- InPAGE NAMEEnter "SuperSimple"
- InPAGE TITLEEnter "SuperSimple"
- InDESCRIPTIONEnter "SuperSimple"
- InVIEW PAGESelectALL USERS
Click "UPDATE"
InMODULESelect"SuperSimple".
Then clickADD.
The module is displayed on the page.
Original address: http://www.adefwebserver.com/DotNetNukeHELP/DNN_ShowMeThePages/
Author of m2land, reproduced please indicate the source, author blog address: http://m2land.cnblogs.com