Hello,
I bind a grid with many employees items. I tried to select the employee whose the key is mentionned in querystring : &EmployeeID=245.
If all items appear in one page, FindItemByKeyValue("EmployeeID",245) returns my item. But if I display items in several pages, the method returns nothing because it only searchs in the page rendered (which is page 1 and I don't know the page for employee 245).
What is the best way to select the "key item" in multi pages without filtering records please ?
Thank you.
I bind a grid with many employees items. I tried to select the employee whose the key is mentionned in querystring : &EmployeeID=245.
If all items appear in one page, FindItemByKeyValue("EmployeeID",245) returns my item. But if I display items in several pages, the method returns nothing because it only searchs in the page rendered (which is page 1 and I don't know the page for employee 245).
What is the best way to select the "key item" in multi pages without filtering records please ?
Thank you.
9 Answers, 1 is accepted
0
Etienne
Top achievements
Rank 1
answered on 27 Jun 2008, 08:19 AM
Do I open a support ticket ?
0
Shinu
Top achievements
Rank 2
answered on 27 Jun 2008, 09:29 AM
Hi,
Try the following code snippet in the PreRender event/
CS:
Thanks
Shinu.
Try the following code snippet in the PreRender event/
CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
foreach (GridDataItem item in RadGrid1.MasterTableView.Items) |
{ |
string strtxt = item.GetDataKeyValue("EmployeeID").ToString(); |
if (strtxt == "245") |
{ |
item.Selected = true; |
} |
} |
} |
Thanks
Shinu.
0
Etienne
Top achievements
Rank 1
answered on 27 Jun 2008, 11:36 AM
Same problem than with FindItemByKeyValue method : key value is searched into the records rendered in the current grid page, not inside all pages of the grid.
My first page contains employeeID from 1 to 10, and the 245 is not found and not selected (it may be in the 15th page).
I can find the page by calculate the position of key value in my DataTable and divide it by grid PageCount, but if your component can find it automatically, it's better !
So, do I need to calculate the page to render or is it a best solution please ?
My first page contains employeeID from 1 to 10, and the 245 is not found and not selected (it may be in the 15th page).
I can find the page by calculate the position of key value in my DataTable and divide it by grid PageCount, but if your component can find it automatically, it's better !
So, do I need to calculate the page to render or is it a best solution please ?
0
Hi Etienne,
My suggestion in this case is to traverse directly all underlying records from the grid source server-side and identify the record of interest by its key value. Some pointers about the approach you can find in this documentation topic:
http://www.telerik.com/help/aspnet-ajax/grdtotalsingridfooters.html (paragraph Displaying totals for all grid pages)
When you find the relevant item in the source, intercept the PreRender event of the grid, switch to the corresponding page (setting the CurrentPageIndex property of the grid), reference the grid row using the FindItemByKeyValue(keyname, keyvalue) method (as you already found out), set the Edit property of the row to true and refresh the grid invoking its Rebind() method.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
My suggestion in this case is to traverse directly all underlying records from the grid source server-side and identify the record of interest by its key value. Some pointers about the approach you can find in this documentation topic:
http://www.telerik.com/help/aspnet-ajax/grdtotalsingridfooters.html (paragraph Displaying totals for all grid pages)
When you find the relevant item in the source, intercept the PreRender event of the grid, switch to the corresponding page (setting the CurrentPageIndex property of the grid), reference the grid row using the FindItemByKeyValue(keyname, keyvalue) method (as you already found out), set the Edit property of the row to true and refresh the grid invoking its Rebind() method.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Etienne
Top achievements
Rank 1
answered on 30 Jun 2008, 02:43 PM
Yes, it's exactly what I did since my first post, and it's working great.
So, I think it should be an interesting adding to the RadGrid to find an item by his key amoung all those of the grid besides those of the current page only.
Thank you for this precision.
So, I think it should be an interesting adding to the RadGrid to find an item by his key amoung all those of the grid besides those of the current page only.
Thank you for this precision.
0
Pablo Tola
Top achievements
Rank 2
answered on 17 Jul 2008, 04:00 PM
Could you post example code of your solution, I'm looking to do the same thing.
thanks.
thanks.
0
Etienne
Top achievements
Rank 1
answered on 05 Aug 2008, 09:51 AM
Sorry for late, I was in holidays...
This is a part of my code wich allows to select grid line of a Primary Key passed in querystring
This is a part of my code wich allows to select grid line of a Primary Key passed in querystring
'select page where key value exists -> allow selecting row below |
Try |
PKValue = CInt(Request.QueryString(_PKName)) |
Catch |
'querystring hacking or bad prog -> PKValue = -1 |
End Try |
If PKValue > -1 Then |
For Each oRow As DataRow In DT.Rows |
IndexKeyValue += 1 |
If CInt(oRow(_PKName)) = PKValue Then Exit For |
Next |
RadGrid1.CurrentPageIndex = IndexKeyValue \ RadGrid1.PageSize |
End If |
RadGrid1.DataBind() |
If Not Page.IsPostBack Then |
Dim it As GridItem = RadGrid1.MasterTableView.FindItemByKeyValue(_PKName, PKValue) 'can't work, find only in rendered page ! |
If Not it Is Nothing Then |
it.Selected = True |
RaiseEvent SelectedIndexChanged(PKValue) |
End If |
End If |
0
ivantkt
Top achievements
Rank 1
answered on 20 Oct 2008, 06:54 PM
Hello, thanks for the coments, you have tell us a good answer, but
a i have the same problem.
I do the solution you suggest, but there is another problem i can't solve.
I do the netx steps:
Find the relevant item in the source, intercept the PreRender event of the grid, switch to the corresponding page (setting the CurrentPageIndex property of the grid), reference the grid row using the FindItemByKeyValue() and select the item (item.Selected = true).
But if i have a grid column sorted ASC, for example: I have a column (clmName) to display the name of an employee, and i sort ASC this column, after this i try to select the item by the steps metioned before, but i get the problem that the DataSource index of the element does not "MATCH", with the index of the grid.
For example
The datasource is this (in this order):
EmployeeNumber EmployeeName Index
1 Zac 0
2 Charli 1
3 Mickey 2
4 Donald 3
The Grid items sorted by EmployeeName (in this order):
EmployeeNumber EmployeeName Index
2 Charli 0
4 Donald 1
3 Mickey 2
1 Zac 3
If i want to select Zac, i find the relevant item in the source, and it index is
DataSourceIndexOfZac = 0;
But does not "MATCH", whit the index display in the grid
GridIndexOfZac = 3;
Can you help Me with this???
a i have the same problem.
I do the solution you suggest, but there is another problem i can't solve.
I do the netx steps:
Find the relevant item in the source, intercept the PreRender event of the grid, switch to the corresponding page (setting the CurrentPageIndex property of the grid), reference the grid row using the FindItemByKeyValue() and select the item (item.Selected = true).
But if i have a grid column sorted ASC, for example: I have a column (clmName) to display the name of an employee, and i sort ASC this column, after this i try to select the item by the steps metioned before, but i get the problem that the DataSource index of the element does not "MATCH", with the index of the grid.
For example
The datasource is this (in this order):
EmployeeNumber EmployeeName Index
1 Zac 0
2 Charli 1
3 Mickey 2
4 Donald 3
The Grid items sorted by EmployeeName (in this order):
EmployeeNumber EmployeeName Index
2 Charli 0
4 Donald 1
3 Mickey 2
1 Zac 3
If i want to select Zac, i find the relevant item in the source, and it index is
DataSourceIndexOfZac = 0;
But does not "MATCH", whit the index display in the grid
GridIndexOfZac = 3;
Can you help Me with this???
0
Hi ivantkt,
Another option is to re-query the underlying datasource, and determine on which page/level the item would be.
This is demonstrated in the code sample attached to this message.
I hope it helps.
Regards,
Yavor
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Another option is to re-query the underlying datasource, and determine on which page/level the item would be.
This is demonstrated in the code sample attached to this message.
I hope it helps.
Regards,
Yavor
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.