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

[Solved] Selected value

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 03 Apr 2009, 12:30 PM
Hi,

with the selectedvalue property i can get the key of the row the user selected.
Is there some way of setting this value as well?

For example a grid with customers with paging enabled : The user clicks on a row to modify the customer. We redirect to a modify customer page and when the user is done on that page we go back to the page with customers.
We know the customers ID and using that i need to reposition the grid on the proper page again.

Does somebody have advice on what the best way is to do this?

Kind regards,
Marco van Kimmenade

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Apr 2009, 08:33 AM
Hello Macro,

You can try out the following code to set the item for the given datakey value, selected and also to move to the selected item page  automatically:
c#:
 protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        int count = RadGrid1.MasterTableView.PageCount;  
        int flag = 0;  
        for (int i = 0; i < count; i++)  
        {  
            RadGrid1.CurrentPageIndex = i;  
            RadGrid1.Rebind();  
             foreach (GridDataItem dataItem in RadGrid1.Items)                     
              
                if (dataItem.GetDataKeyValue("CustomerID").ToString() == customerId)// pass the customer id value here obtained after modification 
                {  
                    dataItem.Selected = true;               
  
                        flag = 1;  
                        break;  
                }   
           if (flag == 1)  
                break;  
        }  
  }  

Thanks
Princy.
Tags
Grid
Asked by
Marco
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or