using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace WebPart
{
[Guid("5d617724-06ed-43c9-9ad0-0d0976d82e7c")]
public class ListAdd : System.Web.UI.WebControls.WebParts.WebPart
{
public ListAdd()
{
}
TextBox txtBH = new TextBox();
TextBox txtYY = new TextBox();
protected override void CreateChildControls()
{
base.CreateChildControls();
System.Web.UI.HtmlControls.HtmlTable table = new System.Web.UI.HtmlControls.HtmlTable();
System.Web.UI.HtmlControls.HtmlTableRow tablerow1 = new System.Web.UI.HtmlControls.HtmlTableRow();
System.Web.UI.HtmlControls.HtmlTableCell tablecell = new System.Web.UI.HtmlControls.HtmlTableCell();
Label lable1 = new Label();
lable1.Text = "输入请假编号:";
tablecell.Controls.Add(lable1);
System.Web.UI.HtmlControls.HtmlTableCell tablecell2 = new System.Web.UI.HtmlControls.HtmlTableCell();
tablecell2.Controls.Add(txtBH);
tablerow1.Controls.Add(tablecell);
tablerow1.Controls.Add(tablecell2);
table.Controls.Add(tablerow1);
tablerow1 = new System.Web.UI.HtmlControls.HtmlTableRow();
tablecell = new System.Web.UI.HtmlControls.HtmlTableCell();
lable1 = new Label();
lable1.Text = "请假原因:";
tablecell.Controls.Add(lable1);
tablecell2 = new System.Web.UI.HtmlControls.HtmlTableCell();
tablecell2.Controls.Add(txtYY);
tablerow1.Controls.Add(tablecell);
tablerow1.Controls.Add(tablecell2);
table.Controls.Add(tablerow1);
this.Controls.Add(table);
Button btnadd = new Button();
btnadd.Text = "新增列表项";
btnadd.Attributes.Add("onclick", "return confirm('确定提交吗?');");
this.Load += new EventHandler(btnadd_onclick);
this.Controls.Add(btnadd);
}
private void btnadd_onclick(object sender, EventArgs e)
{
string qjts = this.txtBH.Text.Trim().ToString();
string qjyy = this.txtYY.Text.Trim().ToString();
if (qjts.Length > 0 && qjyy.Length>0)
{
// Guid listID=(System.Guid)("05e0675b-3125-44fd-bd83-6a434250b1ae");
SPWeb web = SPControl.GetContextWeb(Context);
SPList list = web.Lists["测试列表"];
SPListItemCollection lists = list.Items;
SPListItem listitem = list.Items.Add();
listitem["请假天数"] = qjts;// txtBH.Text;
listitem["请假原因"] = qjyy;// txtYY.Text;
listitem.Update();
this.txtYY.Text = "";
this.txtBH.Text = "";
}
}
}
}