I have a radgrid whose purpose is to allow users to page through a potentially large dataset and export it to excel or csv. At first I was not able to get exporting to work while paging was enabled, but eventually I solved that by binding with the NeedDataSource event. Now I have a weirder problem I can't figure out - the grid does not bind correctly the first time it is loaded, but it does bind correctly the second time. And the export button works fine whether the grid renders or not. Here's the code for the button which shows the grid, the NeedDataSource method, and the declaration of the grid itself:
There aren't any UpdatePanels or anything involved, the page is really pretty simple. And it does all work great the second time the user clicks btnView. But the first time that button is clicked, the grid just renders as a horizontal grey line.
| protected void btnView_Click(object sender, EventArgs e) |
| { |
| grdReport.Visible = true; |
| lblExport.Visible = true; |
| rcbExportFormat.Visible = true; |
| btnExport.Visible = true; |
| } |
| protected void grdReport_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) |
| { |
| SqlCommand cmd = new SqlCommand(filterGrid(), new SqlConnection(Session["Connection"].ToString())); |
| DataTable dt = new DataTable(); |
| new SqlDataAdapter(cmd).Fill(dt); |
| cmd.Dispose(); |
| grdReport.DataSource = dt; |
| } |
| <telerik:RadGrid ID='grdReport' runat='server' OnNeedDataSource='grdReport_NeedDataSource' AutoGenerateColumns='true' Skin='Simple' AllowPaging='true' /> |
There aren't any UpdatePanels or anything involved, the page is really pretty simple. And it does all work great the second time the user clicks btnView. But the first time that button is clicked, the grid just renders as a horizontal grey line.