I maiding a Validiation to my code, and I want to Find Out If a dates from the list are in my Textbox. But I can't view them. How should I List them. I tried Label2.Text += olistaDniSwiatecznych["Data"].ToString(); But nothing happend. Whot schould I write in the Query. Here is all my botton Click method:
protected void Button2_Click(object sender, EventArgs e)
{
SPWeb witryna = SPContext.Current.Web;
// Dodawanie poszczególnych dni projektowych
SPListItemCollection listItems = witryna.Lists["Szczegoly"].Items;
SPListItem item = listItems.Add();
item["Kontrakt"] = TextBox1.Text;
item["Pracownik"] = TextBox2.Text;
item["Dzien"] = TextBox3.Text;
var selectedGroup = DropDownList2.SelectedItem;
item["Procenty"] = new SPFieldLookupValue(int.Parse(selectedGroup.Value), selectedGroup.Text);
string DateOnlyQuery = "<Where><Eq><FieldRef Name='{0}' /><Value Type='DateTime'>{1}</Value></Eq></Where>";
string dateISO = SPUtility.CreateISO8601DateTimeFromSystemDateTime(Convert.ToDateTime(TextBox3.Text).ToUniversalTime().AddHours(2.0));
var query2 = new SPQuery();
query2.Query = String.Format(DateOnlyQuery, "Data", dateISO);
query2.ViewFields = "<FieldRef Name='Data' />";
query2.ViewFieldsOnly = true;
SPListItemCollection listaDniSwiatecznych = witryna.Lists["DR2013 Święta"].GetItems(query2);
foreach (SPListItem olistaDniSwiatecznych in listaDniSwiatecznych)
{
Label2.Text += olistaDniSwiatecznych["Data"].ToString();
}
// Zaktualizowanie wpisu w liscie projektów
item.Update();
DropDownList2.SelectedValue = "2";
this.TextBox1.Text = "";
this.TextBox2.Text = "";
this.TextBox3.Text = "";
Label3.Text = "<span style='color:red; font-size:13px; font-weight:bold;'>Nowy wpis został dodany</span>";
}
If I done like this
SPListItemCollection listaDniSwiatecznych = witryna.Lists["DR2013 Święta"].Items;
foreach (SPListItem olistaDniSwiatecznych in listaDniSwiatecznych)
{
Label2.Text += olistaDniSwiatecznych["Data"].ToString();
}
, it's work perfect, but I want to faster do this by CAML.