Query SharePoint List and write value
I want to query a sharepoint list and return one row and write that row out.
Here is what I have in my ascx page
<table>
<tr>
<td>Name</td>
<td><SharePoint:FieldValue runat="server" FieldName="Name"
Value="Name" /></td>
</tr>
</table>
Here is what I have to retrieve my row
using (SPSite site = new SPSite(webUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList(listName);
if (list != null)
{
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='PatientID' /><Value
Type='Number'>" + PatientID + "</Value></Eq></Where>";
SPListItemCollection items = list.GetItems();
if (items != null)
{
Name = Convert.ToString(items[0]["Name"]);
}
}
}
}
No comments:
Post a Comment