|
12 | 12 | ItemType="Customer" |
13 | 13 | AutoGenerateColumns="false" |
14 | 14 | DataKeyNames="CustomerID" |
| 15 | + SelectMethod="GetCustomers" |
15 | 16 | OnRowCommand="HandleRowCommand" |
16 | 17 | EmptyDataText="No data available"> |
17 | 18 | <Columns> |
|
99 | 100 | private Customer SelectedCustomer; |
100 | 101 | private List<Customer> _customers; |
101 | 102 |
|
102 | | - protected override void OnAfterRender(bool firstRender) |
103 | | - { |
104 | | - if (firstRender) |
105 | | - { |
106 | | - _customers = GetCustomers(); |
107 | | - CustomersGrid.DataSource = _customers; |
108 | | - CustomersGrid.DataBind(); |
109 | | - } |
110 | | - base.OnAfterRender(firstRender); |
111 | | - } |
112 | | - |
113 | 103 | private void HandleRowCommand(GridViewCommandEventArgs args) |
114 | 104 | { |
115 | 105 | if (args.CommandName == "Select") |
|
118 | 108 | int rowIndex = Convert.ToInt32(args.CommandArgument); |
119 | 109 |
|
120 | 110 | // Get the data item for the selected row using the cached data source |
121 | | - if (rowIndex < _customers.Count) |
| 111 | + if (_customers != null && rowIndex < _customers.Count) |
122 | 112 | { |
123 | 113 | SelectedCustomer = _customers[rowIndex]; |
124 | 114 |
|
|
130 | 120 | } |
131 | 121 | } |
132 | 122 |
|
133 | | - private List<Customer> GetCustomers() |
| 123 | + public IQueryable<Customer> GetCustomers(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount) |
134 | 124 | { |
135 | | - return new List<Customer> |
| 125 | + var customers = new List<Customer> |
136 | 126 | { |
137 | 127 | new Customer |
138 | 128 | { |
|
163 | 153 | CompanyName = "Innovation Labs" |
164 | 154 | } |
165 | 155 | }; |
| 156 | + |
| 157 | + // Cache for use in HandleRowCommand |
| 158 | + _customers = customers; |
| 159 | + |
| 160 | + totalRowCount = customers.Count; |
| 161 | + return customers.AsQueryable(); |
166 | 162 | } |
167 | 163 | } |
0 commit comments