我正在做一些改变,我们的网站,并刚刚添加了一个复选框列表,这是很好的工作,但我需要标题的网页改变,当我选择多个复选框。目前,如果没有选择,它会写成“…摘要”)。“然后,当您选择一个复选框时,它会写成“…摘要”“当选中多个复选框时,我需要它说”…摘要“.(多)“我在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 += "®ion=" + selectedRegionString.TrimEnd(',');
Response.Redirect(ResolveUrl(url));
}但我不知道我需要改变什么,如果我找对地方?有人能给我提点建议吗?
发布于 2017-02-15 13:38:36
我使用了在上面的答案中提供给我的内容,并设法将下面的代码片段组合在一起,这是一个不错的方法。
this.Title =“汇总”+ 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;
}发布于 2017-02-14 11:29:27
在客户端处理这个问题是个好主意。
试着跟随
<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){
}
});
});
这将将页面的标题更改为选中的复选框的"Text“属性。
确保您没有设置AutoPostBack="True“。
更新-用于服务器端
要在服务器端处理它,请设置AutoPostBack = "true“
然后在后面的代码中尝试如下
string sTitle = "";
if (CheckBox1.Checked)
{
sTitle += CheckBox1.Text + " ";
}
if (CheckBox2.Checked)
{
sTitle += CheckBox2.Text + " ";
}
this.Title = sTitle;https://stackoverflow.com/questions/42223505
复制相似问题