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

[Solved] How to set Default value for RadGrid

5 Answers 240 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nurmemet Suleiman
Top achievements
Rank 1
Nurmemet Suleiman asked on 17 Dec 2009, 05:30 PM
Hi All,

I need help. I am using RadGrid for Read News page. I want to display one news per page. Also, I have an other page which is news list display. what I am doing is: when user click news title(from news list page) open my read news page(it has RadGrid) and display that news, also on the bottom have page navigator, which is user click next news it will open next news.
My problem is I cannot open user clicked news. It always open my last news. So, I need some one help me to fix this problem.

Thanks.

5 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 17 Dec 2009, 06:01 PM
--
0
Nurmemet Suleiman
Top achievements
Rank 1
answered on 17 Dec 2009, 06:08 PM
Thanks for your reply.

But I could not understand, what is relationship between my question and your answer.

Regards,
0
Schlurk
Top achievements
Rank 2
answered on 17 Dec 2009, 06:19 PM
My apologies, I thought I was replying to another thread!
0
Princy
Top achievements
Rank 2
answered on 18 Dec 2009, 07:01 AM
Hi,


Try the code snippet below to set the selected news item as the default value  on redirect .

        protected void RadGrid1_PreRender(object sender, EventArgs e)  
        {  
            int currentPageIndex = RadGrid1.CurrentPageIndex;  
            for (int i = 0; i < RadGrid1.PageCount; i++)  
            {  
                // Compare NewsID of each item in the current RadGrid page with the selected News ID  
                foreach (GridDataItem item in RadGrid1.Items)  
                {  
                    if (Request.QueryString["NewsID"].ToString().Equals((item["NewsID"].Text)))  
                    {  
                        // Select the item  
                        item.Selected = true;  
                        currentPageIndex = -1; // flag exit  
                        break;  
                    }  
                }  
 
                // If item is found then exit RadGrid page loop  
                if (currentPageIndex.Equals(-1))  
                    break;  
 
                // Go to next RadGrid page  
                currentPageIndex++;  
                if (currentPageIndex >= RadGrid1.PageCount)  
                    currentPageIndex = 0;  
                RadGrid1.CurrentPageIndex = currentPageIndex;  
                RadGrid1.Rebind();  
            }  
             
        }  
 


Thanks,
Princy
0
Nurmemet Suleiman
Top achievements
Rank 1
answered on 18 Dec 2009, 07:15 PM
Thank you very much for your reply,

But, it would not work properly. because, I open new page with brand new RadGrid. the RadGrid bind with code behind. So, Current items id is null. it cannot compare to request.querystring. 

Regards,


Tags
Grid
Asked by
Nurmemet Suleiman
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Nurmemet Suleiman
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or