Mojoportal learning-smartcombo in document translation

Source: Internet
Author: User

Sorry for the poor translation.

 

Smartcombo

During web development, we often encounter the following problem: select an item from a long list. If you use

Drop-down menu, it is very troublesome to select from hundreds of columns. The smartcombo control is used to solve this problem.

Mojoportal already contains this control. If you want to use it in other projects, you can download it from novellforge,

The address is :...

In mojoportal, we use this control. When a user searches for a user, 5-10 pieces of related data are returned based on the user input,

You can select a data entry and return real-time data.

The smartcombo control is used on the parameter configuration page of The mojoportal module.

To use this control, first put the mojoportal. Web. Controls. dll file into the bin folder of your application, and then set the reference.

In the system. Web page section of your web. config file, add a control declaration as follows:

<Pages>
<Controls>
<Add tagprefix = "MP" namespace = "mojoportal. Web. Controls" assembly = "mojoportal. Web. Controls"/>
</Controls>
</Pages>

The page code for adding the smartcombo control is as follows:

<MP: smartcombo id = "scuser" runat = "server"
Dataurl = "../services/userdropdownxml. aspx? Query ="
Showvaluefield = "true"
Valuecssclass = "textlabel"
Valuecolumns = "5"
Valuelabeltext = "userid :"
Valuelabelcssclass = "txtmedblod"
Buttonimageurl = "../data/siteimages/downarrow.gif"
Scriptdirectory = "~ /Clientscript"
Columns = "45"
Maxlength = "50"> </MP: smartcombo>

Dataurl is mapped to a service page, which takes the user's input as the parameter.

If showvaluefield is set to true, the value of the selected item is displayed. For example, if the list in the form is

Userid. Username indicates the value of userid. If it is set to true, username is displayed in the text box.

In many cases, set it to false.

You need to set other parameters according to the actual situation. You need to specify the Javascript file on the scriptdirectory attribute.

The smartcombo control requires the following JS files

SARISSA. js
Sarissa-ieemu-xpath.js
Smartcombo. js

The SARISSA file comes from open-source SARISSA. Simply put, SARISSA provides you with a public API to use Ajax XMLHttpRequest without worrying about the browser type.

To use this control, you must write your own service page so that you can obtain XML files from the data source.
Your XML file must have the same format as the following code. V indicates the value, and t indicates the text.

Writing this page is very simple, as you can see

<? XML version = "1.0" encoding = "UTF-8"?>
<DATA>
<R> <v> 1 </V> <t> user1@foo.com </T> </tr>
<R> <v> 1 </V> <t> user2@foo.com </T> </tr>
<R> <v> 1 </V> <t> user3@foo.com </T> </tr>
<R> <v> 1 </V> <t> user4@foo.com </T> </tr>
<R> <v> 1 </V> <t> user5@foo.com </T> </tr>
</Data>

First, you need an SQL query statement or stored procedure. In my example, I want to return the first few rows of data based on the user name or email address.

Create procedure mp_users_smartdropdown
@ Siteid int,
@ Query nvarchar (50 ),
@ Rowstoget int

As

Set rowcount @ rowstoget
Selct u1.usreid, u1. [name] As siteuser
Form mp_users ul
Where u1.siteid = @ siteid and u1. [name] Like @ query + '%'
Union

Select u2.userid, U2. [email] As siteuser

From mp_users U2

Where u2.siteid = @ siteid and U2. [email] Like @ query + '%'

Order by siteuser
I suppose you know that if you put your data into datareader, if you haven't learned mojoportal source code
For other examples, the next step is to create a. ASPX page for your service. In my program, I created

Services folder. in this folder, I created the userdropdownxml. ASPX page. Note that in the userdropdownxml. aspx file

Declaration part, no content. All the required code is in the userdropdownxml. aspx. CS file.

As follows:

Protected string query = string. empty;

Protected void page_load (Object sender, system. eventargs E)
{
Response. contenttype = "application/XML ";
Encoding encoding = new utf8encoding ();
Xmltextwriter = new xmltextwriter (response. outputstream, encoding );
Xmltextwriter. Formatting = formatting. indented;
Xmltextwriter. writestartdocument ();
Xmltextwriter. writestartelement ("data ");

Sitesettings = siteutils. getcurrentsitesettings ();

If (sitesettings! = NULL) & (siteuser. isinroles ("admins; content administrators ")))
{

If (request. Params. Get ("quer ")! = NULL)
{
Query = request. Params. Get ("query ");
Int rowstoget = 10;
Idatareader reader = siteuser. getsmartdropdowndata (sitesettings. siteid, query, rowstoget );

While (reader. Read ())
{
Xmltextwriter. writestartelement ("R ");

Xmltextwriter. writestartelement ("v ");
Xmltextwriter. writestring (Reader ["userid"]. tostring ());
Xmltextwriter. writeendelement ();

Xmltextwriter. writestartelement ("T ");
Xmltextwriter. writestring (Reader ["siteuser"]. tostring (). Trim ());
Xmltextwriter. writeendelement ();
Xmltextwriter. writeendelement ();
}
Reader. Close ();
}
}

Xmltextwriter. writeendelemnt ();
Xmltextwriter. writeendcocument ();
Xmltextwriter. Close ();
}


If you have better suggestions, please submit them to the developer forum for discussion.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.