Records of two problems

Source: Internet
Author: User
I. DataGrid problem: in the past, when the DataGrid had pagination, "invalid currentpageindex value" often appeared. It must be greater than or equal to 0 and smaller than pagecount ." The error occurs because deleting the last record on the last page will make the page invalid. Alternatively, click search on another page because the page cannot be reached. This problem also occurs. I have been suffering from unexpected solutions!

In fact, it is very easy to understand. If an error occurs, an httpexception will be thrown. Then, before binding data to the DataGrid, use try to catch the exception:

Try
{
Grid. datasource=DT;
Grid. databind ();
}
Catch (Httpexception E)
{
Grid. currentpageindex=0;
Grid. datasource=DT;
Grid. databind ();
}

Solve all problems. Happy... ^-^

2. Question about adding an XML string to XML: Xmldocument xmldoc = New Xmldocument ();

Xmlelement Root = Xmldoc. createelement ( " Config " );
Xmldoc. appendchild (Root ); // Create Root Node

Xmlelement cssnode = Xmldoc. createelement ( " CSS " );
Root. appendchild (cssnode );
Cssnode. innertext = Scssfile; // Create a CSS Node

Xmlelement titlenode = Xmldoc. createelement ( " Title " );
Root. appendchild (titlenode );
Titlenode. innertext = Stitle; // Create a title Node

Xmlelement foldernode = Xmldoc. createelement ( " Folder " );
Root. appendchild (foldernode );
Foldernode. innertext = Sfolder; // Create a folder Node

Xmlelement pagenode = Xmldoc. createelement ( " Pagesize " );
Root. appendchild (pagenode );
Pagenode. innertext = Spagesize; // Create a pagesize Node

Xmlelement datanode = Xmldoc. createelement ( " Datacolumn " );
Root. appendchild (datanode );

String Sxmlcolumn = Removeasp (sdatacolumn ); // Remove ASP: String. Otherwise, an error occurs when saving the XML file. A namespace error is prompted.
String Xmlfile2 = @" <Root> " + Sxmlcolumn + @" </Root> " ; // Add the root node. XML is required.
Xmldocument Doc =   New Xmldocument (); // Add datacolumn subnodes
Doc. loadxml (xmlfile2 );

Xmlelement Node = Doc. documentelement;

Foreach (Xmlnode I In Node. childnodes) // Obtain each subnode
{
Xmlnode xx=Xmldoc. importnode (I,True);//Import nodes from another document
Datanode. appendchild (XX );
}


Xmldoc. Save (sfolder + @" \ Configaspx. xml " );

//// // Edit by 2005-6-8
The namespace error is solved on csdn today. The following is Code : My statement is as follows:
Dim Node As System. xml. xmlnode
Dim Tempnode As Xmlnode
Dim Resourcesnode As Xmlnode
Dim Xmlroot As Xmlnode = Document. documentelement
Dim Nsmgr As Xmlnamespacemanager = New Xmlnamespacemanager (document. nametable)
Nsmgr. addnamespace ( " Xx " , " Http://www.adlnet.org/xsd/adlcp_rootv1p2 " )
 
Tempnode = Xmlroot. selectsinglenode ( " // XX: Organizations/organization/Title " , Nsmgr)
 
' Why can't I parse the XML with a namespace? What should I do?
 
' Answer:
' Prefix is required for each layer
" // XX: Organizations/XX: Organization/XX: Title"

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.