I have wrote code for getting dropdown based value from Sharepoint list.
But it give me error Operation is not valid due to the current state of the object when i set it to textbox.
Please take look of my code.
public void group2_Validating(object sender, XmlValidatingEventArgs e) { // Write your code here. XPathNavigator elementddlCostCenter = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:group1/my:group2/my:ddlFirstName", this.NamespaceManager);
string ddlDepartedFrom = elementddlCostCenter.Value;
XPathNavigator elementddlArrivalAt = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:group1/my:group2/my:ddlLastName", this.NamespaceManager);
string ddlArrivalAt = elementddlArrivalAt.Value;
if (ddlDepartedFrom != null && ddlDepartedFrom != "" && ddlArrivalAt != null && ddlArrivalAt != "")
{
// ListWebServices.Lists listServices = new ListWebServices.Lists();
SPQuery qry = new SPQuery();
string camlquery = "<Where><And><Eq><FieldRef Name='Title' /><Value Type='Text'>" + ddlDepartedFrom + "</Value></Eq>" + "<Eq><FieldRef Name='Categories' /><Value Type='Text'>" + ddlArrivalAt + "</Value></Eq></And></Where>";
// string camlquery = "<Where><Eq><FieldRef Name='Categories'/><Value Type='Text'>"+ ddlArrivalAt +"</Value></Eq></Where>";
qry.Query = camlquery;
SPSite site = null;
SPWeb web = null;
try
{
SPSecurity.RunWithElevatedPrivileges(
delegate()
{
string m_sharepointUrl = "http://ProductionServer";
using (site = new SPSite(m_sharepointUrl))
{
if (site != null)
{
using (web = site.OpenWeb())
{
SPList list = web.Lists["Age"];
if (list != null)
{
DataTable _table = new DataTable();
DataColumn dc = new DataColumn("Mileage");
_table.Columns.Add(dc);
SPListItemCollection listItemsCollection = list.GetItems(qry);
foreach (SPListItem item in listItemsCollection)
{
DataRow _row = _table.NewRow();
_row[0] = SPEncode.HtmlEncode(item["Age"].ToString());
Milage = Convert.ToInt32(SPEncode.HtmlEncode(item["Age"].ToString()));
//Mileage = Convert.ToInt32(_row[0].ToString());
_table.Rows.Add(_row);
}
XPathNavigator domNav = MainDataSource.CreateNavigator();
string xhtmlRTFField = domNav.SelectSingleNode("//my:myFields/my:group1/my:group2/my:txtAge", NamespaceManager).InnerXml;
domNav.SelectSingleNode("//my:myFields/my:group1/my:group2/my:txtAge", NamespaceManager).InnerXml = Milage.ToString(); ---> I got error here
//domNav.SelectSingleNode("//my:myFields/my:group1/my:group2/my:txtAge", NamespaceManager).SetValue(Milage.ToString());
}
web.Close();
}
site.Close();
}
}
}
);
}
catch (Exception ex)
{
}
}
}
Please help on this.
Thank you.