2017-02-14 17 views
0

私はウェブサイトにいくつかの変更を加えています。チェックボックスのリストを追加して、うまくいきましたが、複数のチェックボックスを選択するとページのタイトルが必要になります。 現在のところ、何も選択されていない場合は、 "Summary for ..."と表示されます。次に、 "Summary for ...(チェックボックスの名前)"というチェックボックスを選択すると、 複数のチェックボックスが選択されている場合、 。...(マルチ)」 私はaspx.csにこのコードを発見した:ウェブページのタイトルの変更

public partial class _default : PortalReportPage 
{ 
    public int RegionId { get; set; } 
    public List<int> SelectedRegions { get; set; } 
    public GroupStatisticCollection Stats { get; set; } 
    public CompanyRegionCollection Regions { get; set; } 
    public int PropertyCount { get; set; } 

    protected override void BindPath() 
    { 
     PagePath = PortalPath.GetBasicPath(); 
     PagePath.AddNode(Container.Name, "~/company/default.aspx?id=" + Container.NodeId); 
     PagePath.AddNode("Reports", "~/company/reports.aspx?id=" + Container.NodeId); 
    } 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     // Get all Selected regions into the SelectedRegions variable... 
     SelectedRegions = GetArrayFromQueryString<Int32>("region").ToList(); 

     // TODO: remove this when the sole RegionId is ready to be replaced by the SelectedRegions list 
     if (SelectedRegions.Count > 0) 
     { 
      RegionId = SelectedRegions.First(); 
     } 
     else 
     { 
      RegionId = 0; 
     } 

     GetStatistics(); 

     if (!Page.IsPostBack) 
     { 
      this.Regions = CompanyRegionCollection.GetRegions(Container.NodeId); 

      if (this.Regions != null && this.Regions.Count > 0) 
      { 
       if (this.RegionId == 0) 
       { 
        this.PropertyCount = Regions.Sum(r => r.PropertyCount); 
       } 
       else 
       { 
        if (this.Regions.Any(r => r.NodeId == RegionId)) 
        { 
         this.PropertyCount = Regions.First(r => r.NodeId == RegionId).PropertyCount; 
        } 
       } 
      } 

      if (this.PropertyCount == 0) 
      { 
       if (this.Regions.Count == 0) 
       { 
        this.PropertyCount = PropertyList.GetProperties(PropertyCriteria.NewCriteria(Container.NodeId, PropertyCriteriaSubject.Company)).TotalRecords; 
       } 
      } 

      BindOptionsPanel(); 
     } 

     this.Title = "Summary for " + Container.Name; 

     if (RegionId != 0) 
     { 
      try 
      { 
       this.Title += string.Format(" ({0})", NodeBasic.GetNodeBasic(RegionId).Name); 
      } 
      catch 
      { 

      } 
     } 
    } 

    private void GetStatistics() 
    { 
     Stats = GroupStatisticCollection.GetCategoryStatistics(Container.NodeId, SelectedRegions); 
    } 

    private void BindOptionsPanel() 
    { 
     RegionsChecklist.Items.Add(new ListItem(" All", "0")); 

     foreach (var region in Regions.OrderBy(r => r.Name)) 
     { 
      var item = new ListItem(region.Name, region.NodeId.ToString()); 

      if (SelectedRegions.Contains(region.NodeId)) 
      { 
       item.Selected = true; 
      } 

      RegionsChecklist.Items.Add(item); 
     } 
    } 

    protected void ExportButton_Click(object sender, EventArgs e) 
    { 
     ExportToCsv(this.Stats, this.Title); 
    } 

    protected void RefreshButton_Click(object sender, EventArgs e) 
    { 
     var url = "~/reports/compliance/default.aspx?id=" + Container.NodeId; 

     string selectedRegionString = ""; 

     foreach (ListItem item in RegionsChecklist.Items) 
     { 
      if (item.Selected) 
      { 
       selectedRegionString = selectedRegionString + item.Value + ","; 
      } 
     } 

     url += "&region=" + selectedRegionString.TrimEnd(','); 
     Response.Redirect(ResolveUrl(url)); 
    } 

しかし、私は、私が正しい場所に探していた場合、私は変更する必要があるとわからないのですか? 誰でもそれに関するアドバイスを提供できますか?

+0

エラーは何ですか? – A3006

+0

複数のチェックボックスがオンになっている場合、コンテナ名の代わりに「要約....(マルチ)」と言うためにタイトルを変更する必要があります。私はキャッチの例外を見ても、動作させることができませんでした。 – J32

+1

チェックされたすべてのチェックボックスの文字列を作成し、タイトルに割り当てる必要があります。 – A3006

答えて

0

を以下の私が何をして使用してみてください上記の答えで私に提供され、以下のコードスニペットをまとめて管理しました。

this.Title = "Summary for" + Container.Name;

 if (SelectedRegions.Count > 1) 
     { 
      RegionId = SelectedRegions.First(); 
      this.Title = "Summary for " + Container.Name + " (Multiple Regions)"; 
     } 
     else if (SelectedRegions.Count > 0) 
     { 
      RegionId = SelectedRegions.First(); 
      this.Title += string.Format(" ({0})", NodeBasic.GetNodeBasic(RegionId).Name); 
     } 
     else 
     { 
      RegionId = 0; 
      this.Title = "Summary for " + Container.Name; 
     } 
1

これをクライアント側で処理することは良い考えです。これは、選択したチェックボックスの「テキスト」プロパティにあなたのページのタイトルを変更します

<script type="text/javascript"> 
$(document).ready(function(){ 
    $('input[type="checkbox"]').click(function(){ 
     if($(this).prop("checked") == true){ 
      $(document).attr("title", $(this).next().text()); 
     } 
     else if($(this).prop("checked") == false){ 
     } 
    }); 
}); 

してみてください。

AutoPostBack = "True"に設定していないことを確認してください。

はUPDATE - サーバー側サーバー側でそれを処理するための

については、背後にあるコードに続いてのAutoPostBack = "true" を

を設定

string sTitle = ""; 

      if (CheckBox1.Checked) 
      { 
       sTitle += CheckBox1.Text + " "; 
      } 
      if (CheckBox2.Checked) 
      { 
       sTitle += CheckBox2.Text + " "; 
      } 

      this.Title = sTitle; 
+0

ありがとうございました。私はあなたの助けをありがとう、私はあなたが私に提供したものを取って、それを動作させるために必要なものに使用しました。私はここに来て、役に立つヒントを得ることができる初心者として知っていいです。 – J32

関連する問題