シナリオ :選択したフィルターに基づいて、同じページのリスト ビュー Web パーツに表示されるアイテム/レコードを更新/フィルター処理する必要があります。そこで、ビジュアル Web パーツを作成し、リスト ビュー Web パーツのビューをプログラムで変更しようとしました。これまでのところ、ここまで到達しました:
string spListName = "Job";
protected void BtnSearchClick(object sender, EventArgs e)
{
try
{
SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists[spListName];
XsltListViewWebPart xsltWP = null;
SPWebPartManager wpManager = WebPartManager.GetCurrentWebPartManager(Page) as SPWebPartManager;
//Code to Find List View Web Part on Page
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wpManager.WebParts)
{
if (wp.GetType().Name == "XsltListViewWebPart")
xsltWP = wp as XsltListViewWebPart;
}
oWebsite.AllowUnsafeUpdates = true;
StringBuilder strbPreQuery = new StringBuilder("<Where><Eq>");
StringBuilder strbPostQuery = new StringBuilder("</Value></Eq></Where>");
string strQueryKeyword = "<FieldRef Name='Customer' /><Value Type='Lookup'>";
SPQuery oQuery = new SPQuery();
oQuery.Query = strbPreQuery.ToString() + strQueryKeyword + txtCustomer.Text + strbPostQuery.ToString();
SPListItemCollection itemCol = oWebsite.Lists[spListName].GetItems(oQuery);
PropertyInfo pi = xsltWP.GetType().GetProperty("ContextView", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
SPView view = (SPView)(pi.GetValue(xsltWP, null));
view.Query = oQuery.Query;
view.Update();
wpManager.SaveChanges(xsltWP);
xsltWP.DataBind();
oWebsite.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
Response.Write(ex);
}
}
上記のコードは機能しますが、現在、次の問題に直面しています:
結果の更新にはページの更新が必要なため、次のコードを追加すると、結果は更新されますが、ビジュアル Web パーツのフィルター値が失われます。
this.Context.Response.Redirect(this.Context.Request.Url.ToString());
あるユーザーが適用したフィルターは、別のユーザーにも反映されます。
私が抱えているこれら2つの問題に対処するのを手伝ってもらえますか? それが欲しい
- フィルター値と結果を保持して同時に変更するには
- フィルタリングは、すべてのユーザーではなく、1 人のユーザーに対してのみ行う必要があります。
この点で何か助けていただければ幸いです。