Summary of the Distance Education System

Source: Internet
Author: User
Problems encountered in the online Q & A module and solutions:
In datalist, how does one dynamically bind radiobuttonlist?
You must obtain the questionid bound to each datalistitem in datalist to retrieve the problematic options from the database based on the questionid. How can this problem be obtained?

<% # Zhixia. testonline. Global. copyint (Ref I, Eval ("questionid"). tostring () %>
Declare the variable I on the page, and then obtain the value of <% # eval ("questionid") %> on the page.
Then use the variable I in the datalist_itemdatabound () event.
You can also use int qid = convert. toint32 (datalist1.datakeys [E. Item. itemindex]); to obtain the value of datakey, and set datakey to questionid.
Questionid has been taken out. We can call the method in the Controller to obtain the data, and then bind it.

How can I determine whether the answer is correct?
You must obtain the selected option and the correct answer, that is, the selectindex of radiobuttonlist and the answer value of the current item. It is easy to get the value of radiobuttonlist. If you trigger the selectindexchanged event, you can get it from the trigger object. How can you obtain the answer value?
After thinking about it, I finally figured out that I could store the answer value in the attributes of the radionbuttonlist IN THE datalistitemdatabound event, and then select the tindexchanged event to get the current object of the event and get the attribute value at the same time, you can. In this way, it seems that attributes is really easy to use!

How can I determine whether the data submitted by the current textbox is empty?
Microsoft. VisualBasic... compilerservices has a stringtype class, which has a strcmp function that is very useful.
Directly: If (stringtype. strcmp (textbox2.text, "", false )! = 0 ).

In the design, I used the Enterprise Program Library and dotnetnuke.
Encapsulation:
Encapsulate multiple objects:
Public   Static Idatareader getallquestion ()
{
Return (Idatareader) sqlhelper. executereader (connectionstring, DBO +   " Getallquestion " );
}
Public Arraylist getallquestion ()
{
Return CBO. fillcollection (sqldataprovider. getallquestion (), Typeof (Qinfor ));
}

Encapsulate a single object

Public   Static Idatareader getquestion ( Int Questionid)
{
Return (Idatareader) sqlhelper. executereader (connectionstring, DBO +   " Getquestion " , Questionid );
}
Public Qinfor getquestion ( Int Questionid)
{
Return (Qinfor) CBO. fillobject (sqldataprovider. getquestion (questionid ), Typeof (Qinfor ));
}

In the search module, the following problems are encountered:
How to reflect a class?CodeAs follows:

Public   Static Asearch makesearch ( String Style, String Key)
{
Asearch =   Null ;
Try
{
// Obtain the search type, such as style = topic, and create the theme search entity class and zsearch class. Key is the search keyword
Type type = Type. GetType (style, True );
Guid g = Type. guid;
Object [] Para = New   Object [] {Key };
// Create an object class and provide the Para parameter to initialize the object class, that is, the zsearch class. I thought the abstract function will be initialized here!
Asearch = (Asearch) activator. createinstance (type, para );
Return Asearch;
}
Catch (Typeloadexception ex)
{
System. Console. Write (Ex );
}
Return Asearch;
}

Now we can dynamically obtain entity classes. If you select topic search, you can create a topic class, that is, zsearch class. However, to search for data, you need to call the corresponding stored procedure. It is impossible for us to write the stored procedure name into the program. In this way, we lose the flexibility and the meaning of the factory model. Suddenly, after thinking about the use of the config configuration file, we can dynamically call the name of the stored procedure in the config file to achieve this goal. How can we call a stored procedure?
The config file data is as follows: < Appsettings >
< Add Key = "Searchkecheng" Value = "Searchkecheng" > </ Add >
< Add Key = "Searchjiangshi" Value = "Searchjiangshi" > </ Add >
< Add Key = "Searchzhti" Value = "Searchzhti" > </ Add >
</ Appsettings >

Set the variable value in the object class:
Public String _ SPS = configurationmanager. deleettings ["searchjiangshi"];

In this way, if we want to add a new search method, we can add:
For example, "search all items"
A stored procedure, searchall
A class allsearch inherits the asearch abstract class.
In index. Add "all" to the dropdownlist control of aspx and set the value to "searchall ",
It is worth noting that the value must be consistent with the Class Object Name, otherwise exception will occur.
Well, I have also made a framework chart. You can check it out later! Protected   Void Datalist1_itemdatabound ( Object Sender, datalistitemeventargs E)
{
Radiobuttonlist RBL = (Radiobuttonlist) E. Item. findcontrol ( " Radiobuttonlist1 " );
// Int qid = I;
Int Qid = Convert. toint32 (datalist1.datakeys [E. Item. itemindex]);
// RBL. attributes ["Answer"] = answer;
RBL. attributes [ " Answer " ] = Databinder. eval (E. Item. dataitem, " Answer " ). Tostring ();
RBL. attributes [ " Questionid " ] = Convert. tostring (qid );

qopcontroller QC = New qopcontroller ();
RBL. data source = QC. getoption (qid);
RBL. databind ();
}< br>

Related Article

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.