Application Page:
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"><asp:UpdatePanel ID="panelLV" runat="server" UpdateMode="Conditional"></asp:UpdatePanel>
</asp:Content>
Code behind:
protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack)
{
createLVWP();
}
}
private void createLVWP()
{
}
}
private void createLVWP()
{
SPWeb web = SPContext.Current.Web;
SPList list = web.GetList(
SPUrlUtility.CombineUrl(web.ServerRelativeUrl, myListUrl));
lvwp = new ListViewWebPart();
lvwp.ListName = list.ID.ToString("B").ToUpper();
lvwp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();
lvwp.ChromeType = PartChromeType.None;
SPList list = web.GetList(
SPUrlUtility.CombineUrl(web.ServerRelativeUrl, myListUrl));
lvwp = new ListViewWebPart();
lvwp.ListName = list.ID.ToString("B").ToUpper();
lvwp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();
lvwp.ChromeType = PartChromeType.None;
filterLVWP();
this.panelLV.ContentTemplateContainer.Controls.Add(lvwp);
}
private void filterLVWP()
{
string query = string.Format(
@"<Contains>
<FieldRef Name='myFieldName' /><Value Type='Text'>{0}</Value>
</Contains>", myFieldValue);
XmlDocument doc = new XmlDocument();
doc.LoadXml(lvwp.ListViewXml);
XmlNode queryNode = doc.SelectSingleNode("//Query");
XmlNode whereNode = queryNode.SelectSingleNode("Where");
this.panelLV.ContentTemplateContainer.Controls.Add(lvwp);
}
private void filterLVWP()
{
string query = string.Format(
@"<Contains>
<FieldRef Name='myFieldName' /><Value Type='Text'>{0}</Value>
</Contains>", myFieldValue);
XmlDocument doc = new XmlDocument();
doc.LoadXml(lvwp.ListViewXml);
XmlNode queryNode = doc.SelectSingleNode("//Query");
XmlNode whereNode = queryNode.SelectSingleNode("Where");
if (whereNode != null)
queryNode.RemoveChild(whereNode);
XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "Where", String.Empty);
newNode.InnerXml = query.ToString();
queryNode.AppendChild(newNode);
lvwp.ListViewXml = doc.OuterXml;
}
queryNode.RemoveChild(whereNode);
XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "Where", String.Empty);
newNode.InnerXml = query.ToString();
queryNode.AppendChild(newNode);
lvwp.ListViewXml = doc.OuterXml;
}
Brak komentarzy:
Prześlij komentarz