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

[Solved] GridDropDownColumn - no name in UpdateCommand

5 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
matt
Top achievements
Rank 1
matt asked on 02 Jul 2013, 09:47 PM
hello,

i have a grid using this GridDropDownColumn:

<Telerik:GridDropDownColumn HeaderText="Acceptance" UniqueName="AcceptanceStatus" DataSourceID="odsAcceptanceStatusTypes" ListValueField="ID" ListTextField="Name" ItemStyle-Wrap="false" DropDownControlType="DropDownList" />

which gets its data from a simple DataTable retrieved via a business method call in this ObjectDataSource:

<asp:ObjectDataSource ID="odsAcceptanceStatusTypes" TypeName="MyUtilities.WellTest" SelectMethod="GetAcceptanceStatusTypes" runat="server" />

...the problem -- when I handle the grid's UpdateCommand in C#, I'm not able to refer to this column-value by name. Instead, when I use the below code, the DictionaryEntry for this column is empty (see attached image).

protected void gridItems_UpdateCommand(object source, GridCommandEventArgs e)
{
    GridEditableItem editableItem = e.Item as GridEditableItem;
 
    //get our primary ID from the grid's datasource
    int resultNo = (int)(editableItem.OwnerTableView.DataKeyValues[editableItem.ItemIndex]["Result_No"]);
 
    //get the new values from this edited row
    Hashtable newValues = new Hashtable();
    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editableItem);
 
    int acceptanceStatusTypeID = -1;
 
    foreach (DictionaryEntry entry in newValues)
    {
        switch ((string)entry.Key)
        {
            // (other items removed from code)
 
            //get the value for this
            case "":
                acceptanceStatusTypeID = Int32.Parse((string)entry.Value);
                break;
        }
    }
}

 
...is there a way for me to fix this? i tried giving the GridDropDownColumn a DataField value, but it complained since that value doesn't exist in the grid's source datatable. 

not sure if it makes a difference, but we're on an older version: 2009.2.826.35.

thanks!

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Jul 2013, 05:52 AM
Hi Matt,

I tried to replicate the issue but no avail,it works fine at my end.
Below is the code snippet i tried.

ASPX:
<telerik:RadGrid ID="Radgrid1" runat="server" AutoGenerateColumns="false" AllowPaging="true"
    DataSourceID="SqlDataSource2" AutoGenerateEditColumn="true"
    onupdatecommand="Radgrid1_UpdateCommand">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID" HeaderText="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridDropDownColumn UniqueName="ShipCity" DataSourceID="SqlDataSource2"
                ListTextField="ShipCity" EnableEmptyListItem="true"
                EmptyListItemText="--Choose an option--" EmptyListItemValue="" ListValueField="ShipCity"
                HeaderText="ShipCity" DataField="ShipCity" DropDownControlType="DropDownList" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void Radgrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
  {
      GridEditableItem editableItem = e.Item as GridEditableItem;
      Hashtable newValues = new Hashtable();
      e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editableItem);
      // Your Codes
  }

Please have a look at this documentation for more help.
Updating Values Using InPlace and EditForms Modes

Hope this helps.
Thanks,
Princy
0
matt
Top achievements
Rank 1
answered on 10 Jul 2013, 03:44 PM
Can you show me a screenshot of how the "newValues" dictionary object appears via VS.NET's quickwatch, similar to the one I posted w/ the empty-string value? For yours, what is the GridDropDownColumn's Name portion of the Name/Value pair when using an ObjectDataSource for it?

thanks,
matt 
0
Princy
Top achievements
Rank 2
answered on 11 Jul 2013, 12:27 PM
Hi Matt,

I have attached the screen shots of what i obtained.My GridDropDownColumn is ShipCity.

Thanks,
Princy
0
matt
Top achievements
Rank 1
answered on 18 Jul 2013, 09:38 PM
hi princy,

i see that youre using the DataField="ShipCity" attribute on your GridDropDownColumn. i'm not -- for me, this particular column is not in the underlying datasource that is bound to the grid row.

if you instead use DataField="", what do you get? thats what i use, since putting a value in there when this is not a bound column will break the grid.


thanks,
matt
0
Princy
Top achievements
Rank 2
answered on 19 Jul 2013, 05:10 AM
Hi Matt,

I have tried like what you have said,yes the column name is not visible because,table view's ExtractValuesFromItem(dictonaryObject, editedItem) method,pass it as the first parameter of the ExtractValuesFromItem method. Pass the edited item as the second parameter. The ExtractValuesFromItem method fills the dictionary object with key/value pairs where each key is the DataField of an edited field column and the corresponding value is the new data entered by the user.
So since you haven't set the datafield,that key value is empty.That is why,you are not able to get that column name.
One suggestion is that you may follow any other technique mentioned in the documentation that i have given above,that is,
1)Enable automatic data source operation for the grid,or
2)Fetch the data from each edited field individually through the auto-generated column editors.
Let me know if any concern.


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