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 EventPrivate 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
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.
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
Hope it helps anybody looking for a solution.
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.
Set isbuttonclicked = false (global variable)
in need datasource check
if(ispostback \&& isbuttonclicked)
{
call datalaod function
}