3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 04 Dec 2013, 03:43 AM
Hi Mark,
I'm not clear about your requirement, but to have DropDownList in edit mode you can use a GridTemplateColumn. Please try the below code snippet.
ASPX:
Thanks,
Princy
I'm not clear about your requirement, but to have DropDownList in edit mode you can use a GridTemplateColumn. Please try the below code snippet.
ASPX:
<telerik:GridTemplateColumn HeaderText="City" UniqueName="City"> <ItemTemplate> <%# Eval("City") %> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="City" DataValueField="City"> </asp:DropDownList> </EditItemTemplate></telerik:GridTemplateColumn>Thanks,
Princy
0
Mark
Top achievements
Rank 1
answered on 04 Dec 2013, 01:57 PM
Princy,
Thanks for the reply. My solution is entirely in code-behind. I do not explicitly generate the edit forms, but allow telerik to do it instead. I would like to override one of the text-boxes and replace it with a drop-down-list. Something like "Title of Courtesy" in the following link:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/edit-form-types/defaultcs.aspx
I see that in this demo the edit form is built from the ground up. Is there any way to just replace the text-box that is auto-generated?
Thanks,
Mark
Thanks for the reply. My solution is entirely in code-behind. I do not explicitly generate the edit forms, but allow telerik to do it instead. I would like to override one of the text-boxes and replace it with a drop-down-list. Something like "Title of Courtesy" in the following link:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/edit-form-types/defaultcs.aspx
I see that in this demo the edit form is built from the ground up. Is there any way to just replace the text-box that is auto-generated?
Thanks,
Mark
0
Princy
Top achievements
Rank 2
answered on 05 Dec 2013, 04:33 AM
Hi Mark,
I guess, you want to make a BoundColumn which is TextBox in edit mode to a DropDownList. Please try the sample code snippet.
C#:
Thanks,
Princy
I guess, you want to make a BoundColumn which is TextBox in edit mode to a DropDownList. Please try the sample code snippet.
C#:
RadGrid grid;protected void Page_Init(object sender, System.EventArgs e) { DefineGridStructure(); }private void DefineGridStructure() { grid = new RadGrid(); grid.ID = "RadGrid1"; grid.DataSourceID = "SqlDataSource1"; grid.Skin = "Hay"; grid.AllowPaging = true; grid.AutoGenerateColumns = false; grid.AutoGenerateEditColumn = true; grid.ItemCreated += new GridItemEventHandler(grid_ItemCreated); grid.ItemDataBound += new GridItemEventHandler(grid_ItemDataBound);
grid.MasterTableView.DataKeyNames = new string[] { "OrderID" }; GridBoundColumn boundColumn = new GridBoundColumn(); grid.MasterTableView.Columns.Add(boundColumn); boundColumn.DataField = "OrderID"; boundColumn.HeaderText = "OrderID"; boundColumn = new GridBoundColumn(); grid.MasterTableView.Columns.Add(boundColumn); boundColumn.DataField = "ShipCity"; boundColumn.HeaderText = "ShipCity"; boundColumn.UniqueName = "ShipCity"; this.PlaceHolder1.Controls.Add(grid); }void grid_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem edit = (GridEditableItem)e.Item; TextBox txt = (TextBox)edit["ShipCity"].Controls[0]; txt.Visible = false; //Hide the TextBox DropDownList dropdownlist = new DropDownList(); //Create DropDownList dropdownlist.ID = "dropdownlist1"; dropdownlist.DataSourceID = "SqlDataSource2"; dropdownlist.DataTextField = "ShipCity"; dropdownlist.DataValueField = "ShipCity"; edit["ShipCity"].Controls.Add(dropdownlist); //Add the control to the column } }void grid_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem edit = (GridEditableItem)e.Item; DropDownList drop = (DropDownList)edit.FindControl("dropdownlist1"); drop.SelectedValue = DataBinder.Eval(edit.DataItem, "ShipCity").ToString(); //To set the selected value of the row } }Thanks,
Princy