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

GridDropDownColumn context dependent values

9 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
beth
Top achievements
Rank 1
beth asked on 16 Jun 2008, 11:08 AM
Hi,

I have a rad grid on my web page and I need to do the following.

- Have a GridDropDownColumn that uses values in other columns in the current row to retrieve a list of appropriate values.

We are creating a general ledger code builder and the 4th part of the code is dependent on the 1st 3 parts. So on a row by row basis i need to return the context specific values.

I have a datasource that take two parameters
1) Type this is set ok
2) The portion of the code to return appropriate values for.

How do i pass the values of my columns in to this parameter?
In my edit form i have used the selecting event to set the parameter, but i can't see how i would do this for the grid.

Any help much appreciated

Graham

 

9 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 17 Jun 2008, 04:34 PM
Hi Beth,

If you need to get your item values before RadGrid is rendered, so that you update other data inside the item, you can do it in the ItemDataBound event handler, provided for the exact purpose of manipulating RadGrid data before rendering. In it, you can get your drop down column in the respective item and set its value based on other item cell values.


All the best,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
beth
Top achievements
Rank 1
answered on 19 Jun 2008, 04:44 PM
Hi,

Thankd for the response, I've tried to use the ItemDataBound event, but the grid will not resolve the data in the first row, when the for first loads, it definitely runs the code for the first record, but it doesn't set the value.
I'm using the following code

protected void grdMRU_ItemDataBound(object sender, GridItemEventArgs e)

{

if (e.Item is GridDataItem)

{

string strGL = e.Item.Cells[4].Text;

dstNominalNatural.SelectParameters["strGLNum"].DefaultValue = strGL.Substring(0, 6);

}

}

Also it doesn't set the value in the corresponding edit field when the item goes into edit mode.

Thanks

0
Veli
Telerik team
answered on 20 Jun 2008, 07:26 AM
Hi Beth,

Instead of accessing the item cell by index, please try accessing it by the column's unique name:

GridDataItem item = (GridDataItem)e.Item; 
string strGL = item["ColumnUniqueName"].Text; 


Regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
beth
Top achievements
Rank 1
answered on 20 Jun 2008, 10:38 AM
Hi,

Thanks for the response, the code retrieves the correct value, but it still doesn't set the value for the cell in the first row of the grid.

Process
- There is a datasource on the age which has 1 parameter used to get a list of appropriate values for the gl_natural column in the grid.
-The paramter is the first 6 digits of the gl_code column.
-SO what I'm doing is using the ItemDataBound event to set the default parameter of the datasource each time a new item is bound to the grid. This
works only for rows 2 and on, row 1 doesnot set even though the code is run.

- is this the best way to do this? if so do you know why it isn't working for the first item?
-- could it be a timing issue or overloading the datasource
-- we will typically only have 2 or 3 rows in the grid.
- i now have the edit form working correctly.

Thanks for you help

0
Princy
Top achievements
Rank 2
answered on 20 Jun 2008, 12:11 PM
Hi,

Go through the following help document link.
Accessing cells and rows

Princy.
0
Veli
Telerik team
answered on 20 Jun 2008, 02:07 PM
Hi Beth,

I don't think the ItemDataBound event is the correct place in RadGrid's lifecycle to change data source parameters. The reason for this is that ItemDataBound is fired after the item is bound to data, which means after the required data access for the item. This explains why this approach doesn't work for the first item - simply because the parameter is not set before the item is bound, but is only available for the 2nd and so on items. The best place to initially set this parameter would be the place where you define your data source for RadGrid. Ideally, this is the NeedDataSource event handler, which specifies the data source of RadGrid every time it needs to rebind the data.

In this way, you make sure that the data source parameter is set before the first item is fetched. Please see how this works for you.

Sincerely yours,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
beth
Top achievements
Rank 1
answered on 20 Jun 2008, 02:11 PM
Thanks,

I've moved the code to the ItemCreated event and it now works .

0
Accepted
Shinu
Top achievements
Rank 2
answered on 23 Jun 2008, 06:32 AM
Hi Beth,

You can also refer the following help article.
Distinguishing the major differences between the ItemCreated and ItemDataBound server events

Shinu.
0
Dan Lehmann
Top achievements
Rank 1
answered on 08 Jun 2011, 10:28 PM
Tags
Grid
Asked by
beth
Top achievements
Rank 1
Answers by
Veli
Telerik team
beth
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Dan Lehmann
Top achievements
Rank 1
Share this question
or