I have an issue with the code below..I am trying to populate data from form to list and as well as trying to retrieve data from list using Caml query.(Using same list for entries and quering data)By entering
the ID I will be able to retrieve data from list to form but the user changes data in other parts of the form and populates in the list with the help Of ID first created when next user tries to enter next time same id because of same ids in list its
giving an error..Now i want to retrieve data in such a way that when user enters ID it should retrieve the data by latest entered date so that it will pick the latest entered ID and values..Is it possible or any other approach is required??
protected void Button1_Click(object sender, EventArgs e)
{
SPSite mysite = SPContext.Current.Site;
SPWeb myweb = SPContext.Current.Web;
SPList mylist = myweb.Lists["Entries"];
SPListItem mylistitem = mylist.Items.Add();
mylistitem["ID"] = txtid.Text.ToString();
mylistitem["Test1"] = txttest1.Text.ToString();
mylistitem["Test2"] = txttest2.Text.ToString();
mylistitem["Test3"] = txttest3.Text.ToString();
mylistitem["Test4"] = txttest4.Text.ToString();
mylistitem["Test5"] = txttest5.Text.ToString();
mylistitem["Dropdown"] = ddtest.Text.ToString();
mylistitem["Dropdown1"] = ddtest1.Text.ToString();
mylistitem["Test7"] = test7.Text.ToString();
mylistitem["Test8"] = test8.Text.ToString();
mylistitem["Test9"] = test9.Text.ToString();
mylistitem["Test10"] = test10.Text.ToString();
mylistitem["Test11"] = test11.Text.ToString();
mylistitem["Test12"] = test12.Text.ToString();
mylistitem["Dropdown2"] = ddtest2.Text.ToString();
mylistitem["Dropdown3"] = ddtest3.Text.ToString();
mylistitem["Dropdown4"] = ddtest4.Text.ToString();
mylistitem["Dropdown5"] = ddtest5.Text.ToString();
mylistitem["Test13"] = test13.Text.ToString();
mylistitem["Test15"] =test15.Text.ToString();
mylistitem["Test16"] = test16.Text.ToString();
mylistitem["Date Test"] = DateTimeControl1.SelectedDate;
mylistitem["Date Test1"] = DateTimeControl2.SelectedDate;
mylistitem["Dropdown6"] = ddtesting.Text.ToString();
mylistitem["Test17"] = test17.Text.ToString();
mylistitem["Test18"] = test18.Text.ToString();
myweb.AllowUnsafeUpdates = true;
mylistitem.Update();
myweb.AllowUnsafeUpdates = false;
Label43.Text = "Successfull";
}
protected void Button2_Click1(object sender, ImageClickEventArgs e)
{
SPSite mysite = SPContext.Current.Site;
{
using (SPWeb web = mysite.OpenWeb())
{
//Caml Query for retrieving List data from Project Data list by entering title and populating other columns
SPQuery curQry = new SPQuery();
string Title = this.txtpresales.Text;
curQry.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + Title + "</Value></Eq></Where>";
SPList list = web.Lists["Entries"];
SPListItemCollection curItems = list.GetItems(curQry);
foreach (SPListItem item in curItems)
{
this.test1.Text = item["test1"].ToString();
this.test2.Text = item["test2"].ToString();
this.test3.Text = item["test3"].ToString();
this.test4.Text = item["test4"].ToString();
this.test5.Text = item["test5"].ToString();
this.test6.Text = item["test6"].ToString();
this.test7.Text = item["test7"].ToString();
this.test8.Text = item["test8"].ToString();
this.test9.Text = item["test9"].ToString();
this.test10.Text = item["test10"].ToString();
this.test11.Text = item["test11"].ToString();
this.ddtest1.Text = item["ddtest"].ToString();
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SPSite mysite = SPContext.Current.Site;
SPWeb myweb = SPContext.Current.Web;
SPList mylist = myweb.Lists["Entries"];
SPListItem mylistitem = mylist.Items.Add();
mylistitem["ID"] = txtid.Text.ToString();
mylistitem["Test1"] = txttest1.Text.ToString();
mylistitem["Test2"] = txttest2.Text.ToString();
mylistitem["Test3"] = txttest3.Text.ToString();
mylistitem["Test4"] = txttest4.Text.ToString();
mylistitem["Test5"] = txttest5.Text.ToString();
mylistitem["Dropdown"] = ddtest.Text.ToString();
mylistitem["Dropdown1"] = ddtest1.Text.ToString();
mylistitem["Test7"] = test7.Text.ToString();
mylistitem["Test8"] = test8.Text.ToString();
mylistitem["Test9"] = test9.Text.ToString();
mylistitem["Test10"] = test10.Text.ToString();
mylistitem["Test11"] = test11.Text.ToString();
mylistitem["Test12"] = test12.Text.ToString();
mylistitem["Dropdown2"] = ddtest2.Text.ToString();
mylistitem["Dropdown3"] = ddtest3.Text.ToString();
mylistitem["Dropdown4"] = ddtest4.Text.ToString();
mylistitem["Dropdown5"] = ddtest5.Text.ToString();
mylistitem["Test13"] = test13.Text.ToString();
mylistitem["Test15"] =test15.Text.ToString();
mylistitem["Test16"] = test16.Text.ToString();
mylistitem["Date Test"] = DateTimeControl1.SelectedDate;
mylistitem["Date Test1"] = DateTimeControl2.SelectedDate;
mylistitem["Dropdown6"] = ddtesting.Text.ToString();
mylistitem["Test17"] = test17.Text.ToString();
mylistitem["Test18"] = test18.Text.ToString();
myweb.AllowUnsafeUpdates = true;
mylistitem.Update();
myweb.AllowUnsafeUpdates = false;
Label43.Text = "Successfull";
}
protected void Button2_Click1(object sender, ImageClickEventArgs e)
{
SPSite mysite = SPContext.Current.Site;
{
using (SPWeb web = mysite.OpenWeb())
{
//Caml Query for retrieving List data from Project Data list by entering title and populating other columns
SPQuery curQry = new SPQuery();
string Title = this.txtpresales.Text;
curQry.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + Title + "</Value></Eq></Where>";
SPList list = web.Lists["Entries"];
SPListItemCollection curItems = list.GetItems(curQry);
foreach (SPListItem item in curItems)
{
this.test1.Text = item["test1"].ToString();
this.test2.Text = item["test2"].ToString();
this.test3.Text = item["test3"].ToString();
this.test4.Text = item["test4"].ToString();
this.test5.Text = item["test5"].ToString();
this.test6.Text = item["test6"].ToString();
this.test7.Text = item["test7"].ToString();
this.test8.Text = item["test8"].ToString();
this.test9.Text = item["test9"].ToString();
this.test10.Text = item["test10"].ToString();
this.test11.Text = item["test11"].ToString();
this.ddtest1.Text = item["ddtest"].ToString();
}
}
}
}