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

Button click event and RadGrid

6 Answers 922 Views
Grid
This is a migrated thread and some comments may be shown as answers.
R N
Top achievements
Rank 1
R N asked on 04 Aug 2008, 07:52 PM

I have a page with some search criteria. When the page comes up the first time, I would like to present the page with no data in the grid. And once the user clicks the search button, I would populate the grid with data using the search criteria selected.

    'Search Button Click Event
    Private Sub cmdSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        RadGrid2.DataSource = Data.SubmissionTracking.GetSubmissionDetails()

    End Sub

    'Rad Grid NeedDataSource Event
    Private Sub RadGrid2_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid2.NeedDataSource
        If Not e.IsFromDetailTable Then
            RadGrid2.DataSource = Data.SubmissionTracking.GetSubmissionDetails()
        End If
    End Sub

This is what I see that occurs at runtime:
The page populates with some data even on initial load, because the NeedDataSource event is fired. I would like to avoid that and present the user with no grid.
Also, when the search button is clicked, the NeedDataSource event is fired before the Search button click event. And in some cases, I found that the entire grid events are bypassed (in the sense none of the events get fired on postback).

Please let me know what I may be missing.

Thanks!

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Aug 2008, 07:43 AM
Hi ,

Try with the following approach and see whether it is helpful.

CS:
public static string strtxt; 
    protected void RadGrid2_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
    { 
        if (strtxt == "Bind") 
        { 
            RadGrid2.DataSource = Data.SubmissionTracking.GetSubmissionDetails(); 
            
        } 
         
    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        strtxt = "Bind"
        RadGrid2.Rebind(); 
    } 


Thanks
shinu.
0
R N
Top achievements
Rank 1
answered on 05 Aug 2008, 01:26 PM
Thanks Shinu for your response!
Unfortunately that approach didn't work. Similar to what you suggested, I have a boolean flag which I am setting inside the button click event. I had tried this approach before posting a question here.
What I see happening on button click is that the NeedDataSource event is fired before the Search click event. How can I get around this sequence of events? In the sense have the Search click fire first (set the boolean flag) and then fire the NeedDataSource.

    Dim searchClicked As Boolean = False

    Private Sub cmdSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        searchClicked = True
    End Sub

    Private Sub RadGrid2_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid2.NeedDataSource
        'If Not e.IsFromDetailTable Then
        If searchClicked Then
            GetSubmissionDetails()
        End If
    End Sub

0
R N
Top achievements
Rank 1
answered on 14 Aug 2008, 05:50 PM
I was able to resolve this issue. From an object model perspective, the NeedsDataSource event is fired before the button click event. What I am doing now then is to, have a another datasource in the button event and took out the isfromdetailed table if condition from the needsdatasource event.

Hope it helps anybody looking for a solution.
0
Yavor
Telerik team
answered on 15 Aug 2008, 05:11 AM
Hi R N,

Thank you for sharing your solution with the community.
Another option you may want to try is, with the old setup, calling the RadGrid.MasterTableView.Rebind() method from the click handler. This should call the NeedDataSource handler again. Naturally, the approach that you have found is also suitable.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Louise Collins
Top achievements
Rank 1
answered on 04 Nov 2008, 07:37 PM
Can someone post a project sample for this solution?
0
Naveen
Top achievements
Rank 1
answered on 22 Mar 2017, 01:45 PM

 

Set isbuttonclicked = false (global variable)

 

in need datasource check

if(ispostback \&&  isbuttonclicked)

{

call datalaod function

}

Tags
Grid
Asked by
R N
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
R N
Top achievements
Rank 1
Yavor
Telerik team
Louise Collins
Top achievements
Rank 1
Naveen
Top achievements
Rank 1
Share this question
or