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

RadGrid databinding question

3 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
babymonsta
Top achievements
Rank 1
babymonsta asked on 04 Apr 2011, 10:24 AM
Hi,

I have a page that has a normal asp button and a radgrid. My radgrid uses the NeedDataSource command which is used because my radgrid has paging. However, when my page loads, the needdatasource will trigger and bind my radgrid with data. Is there any way I can load my page and not have the grid bind anything until the user clicks the button thats on my page?

In other words when the page is loaded, the radgrid will be empty, and only have data when the user clicks the button. It works if I remove the needdatasource, but I need this because of my paging. Any advice?

Thanks!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Apr 2011, 10:45 AM
Hello Babymonsta,

One suggestion is to set a Global variable say flag and with initial value 0 and on ButtonClick set the value to 1 and call Rebind() method. And in the NeedDataSource event check for the flag value and populate the grid accordingly.

C#:
int flag = 0;//Global variable
  protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
  {
      if (flag != 1)
          return;
      //code for populating grid
  }
protected void Button1_Click(object sender, EventArgs e)
  {
      flag = 1;
      RadGrid1.Rebind();
  }

Thanks,
Shinu.
0
babymonsta
Top achievements
Rank 1
answered on 04 Apr 2011, 10:46 AM
Is there another way besides this? This way would work but is there a better way or a more appropriate way in handling cases like these?

Thanks!
0
Daniel
Telerik team
answered on 07 Apr 2011, 09:54 AM
Hello,

You can use the following approach provided that you cache the DS:
private object CachedDS
{
   get.... set...
}
 
protected void Page_Init(object sender, EventArgs e)
{
    if (!IsPostBack)
        CachedDS = null;
}
 
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = CachedDS;
}
 
protected void Button1_Click(object sender, EventArgs e)
{
    CachedDS = yourcode;
    RadGrid1.Rebind();
}

Kind regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
babymonsta
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
babymonsta
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or