I have GridDropdownColumn in RadGrid with different source. I wired the DataField, ListValueField and ListTextField all correctly. It doesn't show the value properly when the grid is shown but when edit mode you select the dropdown value it stores is correctly. When displaying in grid, it all shows " " am I missing anything?
Attached the code.
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="true" AllowPaging="true"
PageSize="25" ShowStatusBar="true" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
AllowAutomaticDeletes="True" DataSourceID="PetroSqlDataSource">
<MasterTableView EditMode="Popup" CommandItemDisplay="Bottom" DataSourceID="PetroSqlDataSource"
DataKeyNames="Id" AutoGenerateColumns="false">
<Columns>
<telerik:GridEditCommandColumn />
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" />
<telerik:GridBoundColumn DataField="Id" HeaderText="Unique ID" ReadOnly="True" UniqueName="UniqueID"
Display="false" />
<telerik:GridBoundColumn DataField="SkillId" HeaderText="Skill ID" UniqueName="SkillID" />
<telerik:GridDropDownColumn UniqueName="DropDownListColumn" ListTextField="Discipline"
ListValueField="Discipline" DataSourceID="PetroSqlDataSource2" HeaderText="Discipline"
DataField="Discipline" DropDownControlType="RadComboBox" AllowSorting="true" Display="false">
</telerik:GridDropDownColumn>
<telerik:GridBoundColumn DataField="Discipline" HeaderText="Discipline" UniqueName="Discipline"
ReadOnly="True" />
<telerik:GridBoundColumn DataField="Skill" HeaderText="Skill" UniqueName="Skill" />
<telerik:GridBoundColumn DataField="Description" HeaderText="Description" UniqueName="Description" />
<telerik:GridBoundColumn DataField="Foundation" HeaderText="Foundation" UniqueName="Foundation" />
<telerik:GridBoundColumn DataField="SkillType" HeaderText="SkillType" UniqueName="SkillType" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="PetroSqlDataSource" ConnectionString="<%$ConnectionStrings:PetroTechConnectionString%>"
runat="server" SelectCommand="SELECT [Id],[SkillId], [Discipline],[Skill],[Description], [Foundation],[SkillType] FROM [Skills]"
InsertCommand="INSERT INTO [Skills] ([SkillId],[Discipline],[Skill],[Description],[Foundation],[SkillType]) VALUES (@SkillId,@Discipline,@Skill,@Description,@Foundation,@SkillType)"
UpdateCommand="UPDATE [Skills] SET [SkillId] = @SkillId,[Skill] = @Skill, [Description] = @Description, [Foundation] = @Foundation, [SkillType] = @SkillType WHERE [ID] = @ID"
DeleteCommand="DELETE FROM [Skills] WHERE [Id] = @ID">
<InsertParameters>
<asp:Parameter Name="SkillId" Type="String" Size="10" />
<asp:Parameter Name="Discipline" Type="String" Size="50" />
<asp:Parameter Name="Skill" Type="String" Size="50" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Foundation" Type="Int32" />
<asp:Parameter Name="SkillType" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="PetroSqlDataSource2" ConnectionString="<%$ConnectionStrings:PetroTechConnectionString%>"
runat="server" SelectCommand="SELECT [Id],[Discipline] FROM [Disciplines]">
</asp:SqlDataSource>
28 Answers, 1 is accepted
GridDropDownColumn looks and behaves like a standard GridBoundColumn in browser mode. When in edit mode, however, it displays a drop-down control for each edited cell in the column. Check the following help documentation which explains more about this.
Column Types.
Thanks,
Princy.
Thanks for help but I already seen that page. I know the GridDropdown will be show similar to GridboundColumn but it has to show the selected value right. It is not showing that, it just shows " ". Also in the edit mode, it always defaults to the first on the list and not showing the selected value. I also check out the demo on telerik tv and followed the same but it giving the same output. Check out the output attached.
I just need to show the selected value on the grid and edit modes. It works fine on the insert mode. May be there is a small option which I might be missing out.
Vijai
This issue is already fixed. Download the Latest Internal Build and check it out.
Kind regards,
Iana
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Check the following KB article to download to the latest build.
Updating RadControls for ASP.NET AJAX to another version or license.
Thanks,
Princy.
The lastly described issue is usually due to incorrect configuration of the GridDropDownColumn. However looking at the provided code I can confirm that you did it properly. In order to be able to help further investigate the cause of the problem, I suggest that you open a formal support ticket and send us a runnable version of your code.
Greetings,
Iana
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Thank you for that. I will check it out and turn back to you with my findings.
All the best,
Iana
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
GridDropDownColumn works fine when in edit mode. The list populates and the correct item is selected.
But when in "normal" mode the column displays nothing.
This issue was already cleared in latest version.
so, please update your version.
let me know if you still have any concern.
Thanks,
Jayesh Goyani
I am working in trail version 2011 Q2 Net 40 (VS.Net2010 - .Net Framework 4.0), Still the GridDropDownColumn value is not displayed in View Mode. Can you tell me what version or dll need to install/add for this issue.
regards
Jay
i have not exact idea about version but you can download latest version and check this thing.
let me know if any concern.
Thanks,
Jayesh Goyani
FYI here is the code I am using.
GridDropDownColumn _legacyReinsurerID = new GridDropDownColumn { DataField = "LegacyReinsurerID", HeaderText = "Legacy Reinsurer ID", UniqueName = "LegacyReinsurerID", ListTextField = "LegacyReinsurerID", ListValueField = "LegacyReinsurerID", DropDownControlType = GridDropDownColumnControlType.RadComboBox, HeaderStyle = { Width = Unit.Pixel(140) }, ItemStyle = { Width = Unit.Pixel(140) }, ReadOnly = false, };_reinsurerRadGrid.MasterTableView.Columns.Add(_legacyReinsurerID);private void ReInsurerRadGrid_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { try { string _legacyReinsurerID = ((ReinsuranceAgreementParticipant)(e.Item.DataItem)).LegacyReinsurerID.ToString(); RadComboBox _participantList = (e.Item as GridEditableItem)["LegacyReinsurerID"].Controls[0] as RadComboBox; ReinsuranceAgreementParticipantList _participants = MAASBaseInterface.ReinsuranceAgreementParticipantAPI.GetParticipants(); _participantList.AutoPostBack = true; _participantList.Width = Unit.Pixel(120); _participantList.DataSource = _participants; _participantList.DataValueField = "LegacyReinsurerID"; _participantList.DataTextField = "LegacyReinsurerID"; _participantList.DataBind(); _participantList.SelectedValue = _legacyReinsurerID; _participantList.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(list_SelectedIndexChanged); ((e.Item as GridDataItem)["ParticipantPercentage"].Controls[0] as RadNumericTextBox).Width = Unit.Pixel(75); } catch (Exception ex) { string _ex = ex.Message; } }I would also note that in the
ReInsurerRadGrid_ItemCreated method the below line does contain a value.string _legacyReinsurerID = ((ReinsuranceAgreementParticipant)(e.Item.DataItem)).LegacyReinsurerID.ToStringI tried the same in the latest version 2011.2.712.35 which worked as expected. Try upgrading to the latest version.
Updating RadControls for ASP.NET AJAX to another version or license
Attached is the screenshot.
Thanks,
Princy.
The built-in GridDropDownColumn is designed to be used mainly with DataTables in order to easily map and generate their dropdown items values in conjunction with the DataField/ListValueField/DataSourceID/ListDataMember values of the column. For custom objects collections, which you seem to be using, consider replacing the GridDropDownColumn with template column holding a RadComboBox in its edit template (generating/binding the items for the MS DropDownList inside the ItemDataBound handler of RadGrid).
Regards,
Tsvetina
the Telerik team
ListDataMember = "ID",in the column definition. This solved my display issue in normal mode. Edit mode displays my values in the RadComboBox from a separate data source. I am able to retrieve the columns value which I default the initially loaded value of the RadComboBox when it opens. However I am having a problem wiring up the SelectedIndexChanged event see forum post and yes, I am using myRadComboBox .AutoPostback = true;
I tried this in another grid end it worked on my side. The grid is the second one in this demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/columntypes/defaultcs.aspx
and this is the code I use in ItemCreated:
protected void RadGrid2_ItemCreated(object sender, GridItemEventArgs e){ if (e.Item is GridEditableItem && e.Item.IsInEditMode) { RadComboBox combo = (e.Item as GridEditableItem)["City"].Controls[0] as RadComboBox; combo.AutoPostBack = true; combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged); }}So, as for this part of the code, it should not be a problem.
Can you please elaborate on when and where you dynamically create the column?
Kind regards,
Tsvetina
the Telerik team
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Sales.ascx.cs" Inherits="CharityCheck.Controls.Sales" %><%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %><asp:Panel ID="Panel1" runat="server"> <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server" /> <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="100%" Width="100%" LoadingPanelID="RadAjaxLoadingPanel1"> <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="233px" onitemdatabound="RadGrid1_ItemDataBound" onneeddatasource="RadGrid1_NeedDataSource" oninsertcommand="RadGrid1_InsertCommand" onitemdeleted="RadGrid1_ItemDeleted" oniteminserted="RadGrid1_ItemInserted" onitemupdated="RadGrid1_ItemUpdated" ondeletecommand="RadGrid1_DeleteCommand" onupdatecommand="RadGrid1_UpdateCommand" > <MasterTableView DataKeyNames="ID" commanditemdisplay="Top" commanditemsettings-addnewrecordtext="Add new item" EditMode="InPlace"> <CommandItemSettings AddNewRecordText="Add item" ExportToPdfText="Export to PDF"></CommandItemSettings> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"> </RowIndicatorColumn> <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"> </ExpandCollapseColumn> <Columns> <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" > <HeaderStyle Width="60px" /> </telerik:GridEditCommandColumn> <telerik:GridDropDownColumn HeaderText="Description" DataField="Description" ListTextField="Description" ListValueField="Amount" UniqueName="GridDropDownColumn" DropDownControlType="DropDownList"> </telerik:GridDropDownColumn> <telerik:GridNumericColumn DecimalDigits="2" HeaderText="Price" DataField="Price" UniqueName="Price" ReadOnly="true"> <HeaderStyle Width="100px" /> </telerik:GridNumericColumn> <telerik:GridBoundColumn HeaderText="ID" DataField="ID" ReadOnly="True" UniqueName="ID" Display="False"> </telerik:GridBoundColumn> <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" > <HeaderStyle Width="25px" /> </telerik:GridButtonColumn> </Columns> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn> </EditFormSettings> </MasterTableView> <FilterMenu EnableImageSprites="False"></FilterMenu> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu> </telerik:RadGrid> </telerik:RadAjaxPanel></asp:Panel>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.ComponentModel;using Telerik.Web.UI;using System.Data;using System.Collections;namespace CharityCheck.Controls{ public partial class Sales : CharityCheck.MyUserControl { #region Properties [Browsable(false)] public int CompanyID { get { object obj2 = this.ViewState["CompanyID"]; return (obj2 != null) ? (int)obj2 : 0; } set { this.ViewState["CompanyID"] = value; } } [Browsable(false)] public String Type { get { object obj2 = this.ViewState["Type"]; return (obj2 != null) ? (String)obj2 : ""; } set { this.ViewState["Type"] = value; } } private DataTable GridSource { get { Object obj = this.ViewState["_gds"]; if (obj != null) { return (DataTable)obj; } else { DataTable table = new DataTable("Data"); DataColumn[] keys = new DataColumn[1]; DataColumn colPrimary = table.Columns.Add("ID", System.Type.GetType("System.Int32")); colPrimary.AutoIncrement = true; keys[0] = colPrimary; table.Columns.Add("Description", System.Type.GetType("System.String")); table.Columns.Add("Price", System.Type.GetType("System.Decimal")); table.PrimaryKey = keys; //CharityCheckEntities entities = new CharityCheckEntities(); //var data = (from r in entities.Prices // where r.Type == Type // select r); //foreach (Price price in data) //{ // DataRow row = table.NewRow(); // row["Description"] = price.Description; // row["Price"] = price.Amount; // table.Rows.Add(row); //} this.ViewState["_gds"] = table; return table; } } } #endregion protected void Page_Load(object sender, EventArgs e) { } protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode) { GridEditableItem editedItem = e.Item as GridEditableItem; GridEditManager editMan = editedItem.EditManager; GridDropDownListColumnEditor editor = editMan.GetColumnEditor("GridDropDownColumn") as GridDropDownListColumnEditor; //in case you have RadComboBox editor for the GridDropDownColumn (this is the default editor), //you will need to use ComboBoxControl below instead of DropDownListControl //Then you can modify the list control as per your custom conventions List<Price> items = new List<Price>(); CharityCheckEntities entities = new CharityCheckEntities(); { var data = (from r in entities.Prices where r.Type == Type select r); foreach (Price price in data) { items.Add(price); } } { var data = (from r in entities.MembershipFees where r.Type == Type select r); foreach (MembershipFee fee in data) { Price price = new Price(); price.Description = fee.Description; price.Amount = fee.Amount; items.Add(price); } } editor.DataSource = items; editor.DataBind(); } } protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e) { GridEditableItem editedItem = e.Item as GridEditableItem; GridEditManager editMan = editedItem.EditManager; DataTable table = this.GridSource; DataRow newRow = table.NewRow(); foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns) { if (column is IGridEditableColumn) { IGridEditableColumn editableCol = (column as IGridEditableColumn); if (editableCol.IsEditable) { IGridColumnEditor editor = editMan.GetColumnEditor(editableCol); if (editor is GridDropDownColumnEditor) { newRow["Description"] = (editor as GridDropDownColumnEditor).SelectedText; newRow["Price"] = (editor as GridDropDownColumnEditor).SelectedValue; } } } } table.Rows.Add(newRow); } protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e) { GridEditableItem editedItem = e.Item as GridEditableItem; GridEditManager editMan = editedItem.EditManager; foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns) { if (column is IGridEditableColumn) { IGridEditableColumn editableCol = (column as IGridEditableColumn); if (editableCol.IsEditable) { try { IGridColumnEditor editor = editMan.GetColumnEditor(editableCol); if (editor is GridDropDownColumnEditor) { DataRow[] changedRows = this.GridSource.Select("ID = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ID"].ToString()); changedRows[0]["Description"] = (editor as GridDropDownColumnEditor).SelectedText; changedRows[0]["Price"] = (editor as GridDropDownColumnEditor).SelectedValue; this.GridSource.AcceptChanges(); } } catch (Exception) { e.Canceled = true; break; } } } } } protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e) { string ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString(); DataTable table = this.GridSource; if (table.Rows.Find(ID) != null) { table.Rows.Find(ID).Delete(); table.AcceptChanges(); } } protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { RadGrid1.DataSource = this.GridSource; } protected void RadGrid1_ItemInserted(object sender, GridInsertedEventArgs e) { e.KeepInInsertMode = false; } protected void RadGrid1_ItemUpdated(object sender, GridUpdatedEventArgs e) { e.KeepInEditMode = false; } protected void RadGrid1_ItemDeleted(object sender, GridDeletedEventArgs e) { } }}You could replace the GridDropDownColumn with a GridTemplateColumn having a RadComboBox in the EditItemTemplate. This way, with a few changes in your code you will get the same functionality without the problem the that exists for the dropdown column.
Regards,
Tsvetina
the Telerik team
<telerik:GridDropDownColumn DataField="ChartNumber" HeaderText="Chart" UniqueName="ChartNumber" ListDataMember="ChartNumber" ListValueField="ChartNumber" ListTextField="ChartNumber" ColumnEditorID="gddlChartNumber"> <ItemStyle Width="30px" /> </telerik:GridDropDownColumn>and for GridDropDownListColumnEditor:
<telerik:GridDropDownListColumnEditor ID="gddlChartNumber" runat="server" DropDownStyle-Width="50px" /></div>It is possible that your scenario is not identical. You could open a ticket and provide replication steps for the issue, so we can check what is going on and if there is still a problem on our side.
Regards,
Tsvetina
the Telerik team
I tracked down the issue. In my situation the user can only add one record for each of the values in the dropdown. So I am trimming the recordset used to load the dropdown based on what the user has already defined. The RadGrid is using the data in the dropdown data source to load the value in the grid. In my case it does not find a match in the dropdown recordset and so it displays a blank field. If the grid were to use the data from the data source of the RadGrid instead of the dropdown data source it would work.
I was hoping to use the builtin record editing of the grid but I guess I will have to define my own and just use a GridBoundColumn.
-Mike