I'm having some difficulty binding the GridDropDownListColumnEditor for an "InPlace" insert on a grid that is initially loaded with no records. I've gone through the forums, and I've implemented several of the suggested solutions to no avail. The DropDownList displays with no records bound to it. Am I doing something wrong?
To provide some context, I am looking to avoid SqlDataSource controls, as it would break away from our current architecture. I was able to bind the grid by using a SqlDataSource and setting the DataSourceID property of the GridDropDownColumn, but in doing that, I lost the formatting provided by the columneditor control.
Please advise...
Here is my code (ASPX):
And my code behind OnItemDataBound event:
Thanks!
To provide some context, I am looking to avoid SqlDataSource controls, as it would break away from our current architecture. I was able to bind the grid by using a SqlDataSource and setting the DataSourceID property of the GridDropDownColumn, but in doing that, I lost the formatting provided by the columneditor control.
Please advise...
Here is my code (ASPX):
| <telerik:RadGrid ID="grdClientAddresses" runat="server" |
| OnItemDataBound="grdClientAddress_ItemDataBound" |
| Visible="true" |
| AutoGenerateColumns="false" |
| Skin="Office2007" |
| Width="800" |
| AllowPaging="true"> |
| <MasterTableView |
| EditMode="InPlace" |
| CommandItemDisplay="Top" |
| DataKeyNames="ClientAddressID"> |
| <CommandItemSettings |
| AddNewRecordText="New Address" |
| AddNewRecordImageUrl="/images/office.png" |
| RefreshText="Reload" /> |
| <NoRecordsTemplate> |
| No addresses exist for this client. Use the fields above to create a new address |
| </NoRecordsTemplate> |
| <Columns> |
| <telerik:GridBoundColumn UniqueName="Address_StreetAddress" |
| HeaderText="Street Address" |
| ColumnEditorID="StreetAddressColumnEditor" |
| HeaderStyle-Width="400" |
| ItemStyle-Width="400" |
| DataField="StreetAddress"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn UniqueName="Address_City" |
| HeaderText="City" |
| ColumnEditorID="CityColumnEditor" |
| DataField="City" |
| HeaderStyle-Width="260" |
| ItemStyle-Width="260"> |
| </telerik:GridBoundColumn> |
| <telerik:GridDropDownColumn UniqueName="Address_StateID" |
| DataField="StateID" |
| ColumnEditorID="StateColumnEditor" |
| HeaderText="State" |
| HeaderStyle-Width="50" |
| ItemStyle-Width="50"> |
| </telerik:GridDropDownColumn> |
| <telerik:GridBoundColumn UniqueName="Address_ZipCode" |
| HeaderText="Zip" |
| DataField="Zip" |
| ColumnEditorID="ZipCodeColumnEditor" |
| HeaderStyle-Width="90" |
| ItemStyle-Width="90"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| <telerik:GridDropDownListColumnEditor ID="StateColumnEditor" runat="server" |
| DataTextField="StateAbbr" |
| DataValueField="StateID" |
| DropDownStyle-Width="50"> |
| </telerik:GridDropDownListColumnEditor> |
| <telerik:GridTextBoxColumnEditor ID="StreetAddressColumnEditor" runat="server" |
| TextBoxStyle-Width="350"> |
| </telerik:GridTextBoxColumnEditor> |
| <telerik:GridTextBoxColumnEditor ID="CityColumnEditor" runat="server" |
| TextBoxStyle-Width="220"> |
| </telerik:GridTextBoxColumnEditor> |
| <telerik:GridTextBoxColumnEditor ID="ZipCodeColumnEditor" runat="server" |
| TextBoxStyle-Width="60"> |
| </telerik:GridTextBoxColumnEditor> |
And my code behind OnItemDataBound event:
| protected void grdClientAddress_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item.IsInEditMode) |
| { |
| if (e.Item is GridEditableItem) |
| { |
| //first reference the edited grid item |
| GridEditableItem EditableItem = e.Item as GridEditableItem; |
| GridEditManager EditableItemMgr = EditableItem.EditManager; |
| //reference the column editor which holds the dropdown list instance in the edit form |
| GridDropDownColumnEditor StateDropDownEditor = EditableItemMgr.GetColumnEditor("Address_StateID") as GridDropDownColumnEditor; |
| //bind the column editor |
| StateDropDownEditor.DataSource = base.DataPortal.GetStates(); |
| StateDropDownEditor.DataTextField = "StateAbbr"; |
| StateDropDownEditor.DataValueField = "StateID"; |
| StateDropDownEditor.DataBind(); |
| StateDropDownEditor.SelectedIndex = 0; |
| } |
| } |
| } |
Thanks!