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

ListTextField and ListValueField

3 Answers 129 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Silvio Silva Junior
Top achievements
Rank 2
Silvio Silva Junior asked on 30 Mar 2010, 03:16 PM
Hello guys.

I have a GridDropDownColumn that is binded in needDataSource event. The GridDropDownColumn's properties is show below:

<telerik:GridDropDownColumn DataField="A017_dsc_tip" HeaderText="Tipo" ListDataMember="T017_tipo_telefone" 
SortExpression="A017_dsc_tip" ListTextField="A017_dsc_tip" ListValueField="A017_dsc_tip" UniqueName="A017_dsc_tip"
</telerik:GridDropDownColumn> 

Using the column like this, I have no problem with my grid, and I have some like:

Grid correct

but, I can't take the "ID" of the item, and when in editmode, I can't set the current item correctly. If I change the ListValueField to the correct data field I have some like this:

Grid incorrect

my server code is below:

protected void gdvTelefone_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editedItem = e.Item as GridEditableItem; 
            GridEditManager editMan = editedItem.EditManager; 
 
            //Setando o dropdownlist dos tipos de telefone 
            GridDropDownListColumnEditor A017_dsc_tip = editMan.GetColumnEditor("A017_dsc_tip"as GridDropDownListColumnEditor; 
            string selectedValue = A017_dsc_tip.SelectedValue; 
            ObjectQuery<T017_TIPO_TELEFONE> query = entities.T017_TIPO_TELEFONE; 
            A017_dsc_tip.DataSource = query.AsQueryable(); 
            A017_dsc_tip.DataTextField = "A017_dsc_tip"
            A017_dsc_tip.DataValueField = "A017_cod_tip"
            A017_dsc_tip.DataBind(); 
            A017_dsc_tip.SelectedValue = selectedValue; 
        } 
    } 

What it not work? I'm following this thread:

http://www.telerik.com/community/forums/aspnet-ajax/grid/binding-programmatically.aspx

Thanks in advance.

Regards.

3 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 30 Mar 2010, 03:26 PM
Hello Silvio Silva Junior,

Have you tried setting A017_dsc_tip.SelectedValue to (string) e.Item.DataItem["A017_dsc_tip"]?

Regards,
Simon
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
Silvio Silva Junior
Top achievements
Rank 2
answered on 30 Mar 2010, 03:34 PM
Hello Dear admin.

Tx for your fast answer.

I have this error for the code that you have showed:

Cannot apply indexing with [] to an expression of type 'object'  

Tx.

Regards.



0
Accepted
Simon
Telerik team
answered on 30 Mar 2010, 03:50 PM
Hello Silvio Silva Junior,

Please excuse me for my omission - you need to first cast the DataItem object to the underlying data type before accessing its fields.

For instance if you bind the Grid to a SqlDataSource you can cast the DataItem to DataRowView, e.g.
DataRowView dataItem = (DataRowView) e.Item.DataItem;
string value = dataItem["A017_dsc_tip"];

Greetings,
Simon
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
ComboBox
Asked by
Silvio Silva Junior
Top achievements
Rank 2
Answers by
Simon
Telerik team
Silvio Silva Junior
Top achievements
Rank 2
Share this question
or