您好,
取参数的值字段,使用的方法是:
1.使用JS从前台取到选择的label
- <script>
- function appendParam() {
-
- var arr = [];
-
- arr.push($("#parametersPane .parameterTextBox").val());
- arr.push($("#parametersPane .parameterComboBox option:selected" ).text());
-
- $("#parametersPane .parameterListBox input:checked").each(
- function () {
- var t = $(this).next().text();
- arr.push(t);
- }
- );
-
- $('#subForm').append('<input type="hidden" name="paramCount" value="' + arr.length + '">');
- arr.forEach(function (item, i, arr) {
- $('#subForm').append('<input type="hidden" name="param' + i + '" value="' + item + '">');
- });
- return true;
- }
- </script>
复制代码
2.在后台参数取到label和value的对应关系
- var paramsInReport = _reportDef.Report.ReportParameters[2].ValidValues;
- Dictionary<string, string> allValidParams = new Dictionary<string, string>();
- foreach (var param in paramsInReport.ParameterValues)
- {
- var p = (ParameterValue)param;
- allValidParams.Add(p.Label, p.Value);
- }
复制代码
3.将value赋值给报表
- for (int i = 0; i < paramCount; i++)
- {
- string paramKey = "param{0}";
- if (i < 2)
- {
- numberParam = i;
- }
- else
- {
- numberParam = 2;
- }
- paramKey = string.Format(paramKey, i);
- string param = Request[paramKey];
- if (numberParam < 2)
- {
- _reportDef.Report.ReportParameters[numberParam].DefaultValue.Values.Add(param);
- }
- else
- {
- if (allValidParams.ContainsKey(param))
- _reportDef.Report.ReportParameters[numberParam].DefaultValue.Values.Add(allValidParams[param]);
- }
- }
复制代码
效果截图:
示例代码:
|