To add data entries to the list, you can use
Splistitemcollection Class
Add Method To create a list item object, and then call
Splistitem Class
Update Method to write a new item to the database.
The following example assumes that there are five Textbox, one to specify the name of the list to be added, and the other four to specify the added value. Collect information from these five input sources through indexes.
Note: :
In this example, Microsoft. Sharepoint. spcontent class members are used to obtain the current website set, website, and list. In addition to the HTTP context, such as in a command line application or a Windows application, this method cannot be used.
VB
Dim Mysite As Spweb = Spcontext. Current. Web
Dim Listitems As Splistitemcollection
= Mysite. Lists (textbox1.text). Items
DimItemAsSplistitem=Listitems. Add ()
Item ( " Title " ) = Textbox2.text
Item ( " Stock " ) = Convert. toint32 (textbox3.text)
Item ( " Return date " ) = Convert. todatetime (textbox4.text)
Item ( " Employee " ) = Textbox5.text
Item. Update ()
C #
Spweb mysite = Spcontext. Current. Web;
Splistitemcollection listitems = Mysite. Lists [textbox1.text]. items;
Splistitem item=Listitems. Add ();
Item [ " Title " ] = Textbox2.text;
Item [ " Stock " ] = Convert. toint32 (textbox3.text );
Item [ " Return date " ] = Convert. todatetime (textbox4.text );
Item [ " Employee " ] = Textbox5.text;
Item. Update ();
}
CodeFirstAddMethod To createSplistitemObject. Then, specify the field value by using the index on the list item. For example, item ["title"] specifies the value of the title bar of the list item. Finally, the Code callsUpdateMethod: Write the change back to the database.
The above example must reference the Microsoft. SharePoint namespace.
If the list item to be created contains the metadata to be retained, we can useAuthor,Editor,CreatedAndModifiedThe field is used as the index, whereAuthorOrEditorSpecify a WSS userID. For more information, seeSplistitemClass.
To delete a project from the list, we can use the delete method of the splistitemcollection class. This method requires the index of the set as the parameter.
VB
Dim Mysite As Spweb = Spcontext. Current. Web
Dim Listitems As Splistitemcollection
= Mysite. Lists (textbox1.text). Items
Dim Itemcount As Integer = Listitems. Count
Dim K As Integer
for K = 0 to itemcount - 1
dim item as splistitem = listitems (k)
IfTextbox2.text=Item ("Employee"). Tostring ()Then
Listitems. Delete (k)
End If
NextK
C #
Spweb mysite = Spcontext. Current. Web;
Splistitemcollection listitems = Mysite. Lists [textbox1.text]. items;
Int Itemcount = Listitems. count;
for ( int K = 0 ; k itemcount; k ++ )
{< br> splistitem item = listitems [k];
If(Textbox2.text=Item ["Employee"]. Tostring ())
{
Listitems. Delete (k );
}
}
Based on the input information in the two Textbox, the Code traverses the data item set in the specified list and deletes the data item whose employee field is the specified value.
The above example must reference the Microsoft. SharePoint namespace.