Thursday, November 24, 2016

Adding a grid view filter (Part II)

  • Add the following java scripts and styles in the header section.

[code] [/code]

[code] [/code]

[code] [/code]


  • Add this code for create the grid.
<div id="example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap4">
    <div class="row">
        <div class="col-md-6">
            <div class="dataTables_length" id="example_length"></div>
        </div>
        <div class="col-md-6">
            <div id="example_filter" class="dataTables_filter">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <table id="tbAllStockBal" class="table table-striped table-bordered dataTable" role="grid" aria-describedby="example_info" style="width: 100%;">
                <thead>
                    <tr role="row">
                        <th class="sorting_asc" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Position: activate to sort column descending" style="width: 0px;" aria-sort="ascending">Txn Date</th>
                        <th class="sorting" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Name: activate to sort column ascending" style="width: 0px;">Ref No</th>
                        <th class="sorting" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Office: activate to sort column ascending" style="width: 0px;">Memo</th>
                        <th class="sorting" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Age: activate to sort column ascending" style="width: 0px; text-align: right;">Line Description</th>
                        <th class="sorting_asc" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Position: activate to sort column descending" style="width: 0px;" aria-sort="ascending">Line Received</th>
                        <th class="sorting" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Name: activate to sort column ascending" style="width: 0px;">Line Payment</th>
                        <th class="sorting" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Office: activate to sort column ascending" style="width: 0px;">Total Received</th>
                        <th class="sorting" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Age: activate to sort column ascending" style="width: 0px; text-align: right;">Total Payment</th>
                    </tr>
                </thead>
                <tbody>
                    <%=getPayments()%>
                </tbody>
            </table>
        </div>
    </div>
</div>


  • In code behind, create the getPayments() method as below

[code] public string getPayments() { string data = ""; try { DataTable dt = searchPaymentService.getPayments(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; string TxnDate = Convert.ToDateTime(dr["TxnDate"]).ToString("dd-MM-yyyy"); string RefNo = dr["RefNo"].ToString(); string Memo = dr["Memo"].ToString(); string LineDescription = dr["LineDescription"].ToString(); string LineReceived = dr["LineReceived"].ToString(); string LinePayment = dr["LinePayment"].ToString(); string Received = dr["Received"].ToString(); string Payment = dr["Payment"].ToString(); [/code]

                        data += "<tr><td>" + TxnDate + "</td><td>" + RefNo + "</td><td>" + Memo + "</td><td>" + LineDescription + "</td><td>" + LineReceived + "</td><td>" + LinePayment + "</td><td>" + Received + "</td><td>" + Payment + "</td></tr>";


[code] } } return data; } catch (Exception ex) { return data; } [/code]





Load multiple RDLC reports at the same time


When there are multiple RDLC reports and you want to load data to that reports at the same time, set AsyncRendering="false" in every report without one report.

Thursday, November 17, 2016

Find the index of current row in Grid View

Assume there is a control within a grid view template field. On the TextChanged event, we can get the selected index as below.

[code]
int index = ((GridViewRow)(((TextBox)sender).Parent.Parent)).RowIndex;
[/code]

Wednesday, November 16, 2016

Format RDLC report to export to an excel, group wise with expanded data

  • Bind data to a dataset.
  • Use a matrix to present the data.
  • If you want expanded data within the group, the highlighted check box should be unchecked.

  • If you want to export this report to an excel sheet wise by name, it can be done by changing page break options under Group Properties.

Show report header on all work sheets
  • Click that small drop down arrow at the right corner of column groups as below.

  • Select the first static member under Row Groups, and set "KeepWithGroup" as After and "RepeatOnNewPage" as True.



  • This will now copy the headers on all worksheets.





Reference: Generate Multiple Worksheets by Groups in SSRS Exported Excel Spreadsheets