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"