This is a migrated thread and some comments may be shown as answers.

[Solved] Odd binding problem

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 30 Oct 2009, 08:03 PM
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:

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.


1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Nov 2009, 07:28 AM
Hi,

I assume that your grid is hidden initially and  displayed on clicking the btnView button. You would need to Rebind the grid after setting its visible state to true.

protected void btnView_Click(object sender, EventArgs e)  
        {  
            grdReport.Visible = true;  
            grdReport.Rebind(); 
            lblExport.Visible = true;  
            rcbExportFormat.Visible = true;  
            btnExport.Visible = true;  
        }  


Thanks,
Shinu
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or