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

hiding the radgrid if no rows are bound

5 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 25 Sep 2008, 04:36 PM
If RadGrid.rows.count = 0 then
RadGrid.visible = False
else
RadGrid.visible = True
End If

is this possible?

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Sep 2008, 04:15 AM
Hi Jeff,

Try the following code snippet to achieve the desired scenario.

CS:
  protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
       int RowCountRadGrid1.MasterTableView.Items.Count; 
       if (RowCount == 0) 
       { 
           RadGrid1.Visible = false
       } 
       else 
           RadGrid1.Visible = true
  } 

You can also go through the following help article.
Visible/Invisible conventions

Thanks
Shinu.
0
Jeff
Top achievements
Rank 1
answered on 27 Sep 2008, 04:15 PM

if i set a break point on this and comment out the if logic - i run the page - initally nothing is bound from an object datasource - it steps through it and i can mouse over to seee that rowcount = 0 - so far so good - when i select something from the tree view and step through it stops and i can determine that the rowcount = 27 - but that's only when the if logic is commented out - if i uncomment the if logic and select something from the tree view - it does not step through this block like it never gets called. I've tried it from both within the radajax panel and out of it. please advise.

protected

void RadGrid2_DataBound(object sender, EventArgs e)
{
    int rowcount = RadGrid2.MasterTableView.Items.Count;
    if (rowcount < 1)
    {
        RadGrid2.Visible =
false;
    }
    else
    {
        RadGrid2.Visible =
true;
    }

}

0
Jeff
Top achievements
Rank 1
answered on 29 Sep 2008, 07:08 PM
i also tried this in the prerender area as well - please advise
0
Veli
Telerik team
answered on 29 Sep 2008, 08:49 PM
Hello Jeff,

How do you bind your RadGrid? Please see if you can move all RadGrid-binding code to the NeedDataSource event and only set the data source for the respective tree view item. Then implement the below code snippet in RadGrid's PreRender event. Please share with us your observations.

Sincerely yours,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jeff
Top achievements
Rank 1
answered on 30 Sep 2008, 05:17 PM
via the object datasource.

if i do this - it doesn't showand the event is never called

 int RowCountRadGrid1.MasterTableView.Items.Count; 
       if (RowCount == 0) 
       { 
           RadGrid1.Visible = false
       } 
       else 
           RadGrid1.Visible = true
  
but if i do this - the event is called and a mouse over of count shows me a number greater than 0
 int RowCountRadGrid1.MasterTableView.Items.Count; 
       //if (RowCount == 0) 
       //{ 
        //   RadGrid1.Visible = false
       //} 
       //else 
          // RadGrid1.Visible = true
  
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jeff
Top achievements
Rank 1
Veli
Telerik team
Share this question
or