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

Problem with binding objectDataSource to GridDropDownColumn in RADGrid

3 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 07 May 2010, 07:38 AM
Dear,

I want to bind the RADGrid with ObjectDatasource. One of the properties of the object is a BusinessAreaKey. Hence my object only have Key (e.g 'FIN' for fianancial Services). I have to show the user 'Financial Services' as buiness area instead of key 'FIN'. I have stored all the business Areas in xml file as Key-value pairs. So I read the xml data in objectDataSource as BusinessAreas.
I am using GridDropdownColumn to show the business areas. In RADGrid1_ItemDatabound() event, I am binding the column with the list of available business Areas with the check that item is an EditItem.
Problem that I am facing is: When RADGrid is initially loaded, I don't see the data in BunessAreas column. But when I click to update any row, business areas in all the rows below shows me correct values as expected.

protected

void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

{

 

 

 

BLL.DealflowCompany dfCompany = null;

string idString ="";

if (e.Item.ItemType== GridItemType.EditItem)

{

 

GridEditableItem editedItem = e.Item as GridEditableItem;

GridEditManager editMan = editedItem.EditManager;

GridDropDownListColumnEditor editor =

editMan.GetColumnEditor("BusinessAreaKey") as GridDropDownListColumnEditor;

 

try{// Exception for new Item

 

idString = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString();

if (!string.IsNullOrEmpty(idString))

{

dfCompany = BLL.DealflowCompany.FromID(Convert.ToInt32(idString));

editor.DropDownListControl.SelectedValue = dfCompany.BusinessAreaKey;

}

}

catch{}

 

if(editor!=null)

{

editor.DataSource = LBOffice.Website.Language.GetBusinessAreas(Session["language_path"].ToString());

editor.DataTextField="Area";

editor.DataValueField = "Key";

editor.DataBind();

if(dfCompany!=null)

editor.SelectedValue = dfCompany.BusinessAreaKey;

 

}

 

 

 

 

}


I will appreciate if you can help me in resolving this issue.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 12 May 2010, 09:51 AM
Hello Sarjeet,

You could try setting the value to the GridDropDownColumn when RadGrid is in view mode, in  RadGrid.ItemDataBound event handler with the following code snippet:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
   {
       GridDataItem item = e.Item as GridDataItem;
       item["GridDropDownColumn"].Text = value;
   }
}

Additionally I am sending you a simple example which demonstrates how to achieve the desired functionality. Please check it out and let me know if it helps you.

Greetings,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
David
Top achievements
Rank 1
answered on 13 May 2010, 06:33 AM
Thank you Radoslav,

Now I am able to see the values in view mode.
Another problem I am facing right now is that when I do filtering, it is not allowing me with "Value" instead allowing me with "Key". Since user is not aware of the Keys, I have to do filtering as per the values. For example, to filter all the companies in Financial sector, user should be able to filter by providing 'Financial' in the filter textbox. Right now filtering give correct result only when I enter "FIN" key in filter textbox.
Please help me how can I achieve this fuctionality.
Thanks for your help in advance.
0
Radoslav
Telerik team
answered on 13 May 2010, 01:15 PM
Hello Sarjeet,

In your case you could try setting the GridDropDownColumn.DataField value to the "Area". However in this case you need to have this field into the result set returned from the database when a SqlDataSource.SelectCommand is executed.
For example if you have two tables - Companies and Sectors. The Sectors table has ID and Name columns. Each row from the Companies table contains the ID of the specific sector from Sectors table. In this example you could join the two tables and create a result set. Then you could bind the RadGrid to it and set the GridDropDownColumn.DataField property to the "Name", instead of "ID". Then when you perform filtering, the RadGrid will filter Companies by Sectors's "Name" column.

I hope this helps.

Greetings,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
David
Top achievements
Rank 1
Share this question
or