9 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 25 Nov 2009, 09:35 AM
Hi Pradeep,
You can use a GridTemplateColumn with a label in its ItemTemplate and a dropdownlist in its EditItemTemplate:
aspx:
Thanks
Shinu.
You can use a GridTemplateColumn with a label in its ItemTemplate and a dropdownlist in its EditItemTemplate:
aspx:
| <telerik:GridTemplateColumn UniqueName="TemplateColumn"> |
| <ItemTemplate> |
| <asp:Label ID="lblStatus" runat="server" Text='<%#Eval("Status") %>'>'></asp:Label> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <asp:DropDownList ID="ddlStatus" AppendDataBoundItems="true" SelectedValue='<%#Eval("Status") %>' runat="server"> |
| <asp:ListItem Text=""></asp:ListItem> |
| <asp:ListItem Text="Closed"></asp:ListItem> |
| <asp:ListItem Text="Open"></asp:ListItem> |
| </asp:DropDownList> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
Thanks
Shinu.
0
pradeep k
Top achievements
Rank 1
answered on 25 Nov 2009, 09:42 AM
thank you.
0
pradeep k
Top achievements
Rank 1
answered on 25 Nov 2009, 01:13 PM
I have one more issue here,
'ddlStatus' has a SelectedValue which is invalid because it does notexist in the list of items.
if i do like what you said, it is working fine with edit mode, but gives error in insert mode.
error is
'ddlStatus' has a SelectedValue which is invalid because it does notexist in the list of items.
Parameter name: value"
Please help me regarding this.
0
pradeep k
Top achievements
Rank 1
answered on 25 Nov 2009, 01:19 PM
sorry,
i got the issue.
i forgot to write " <asp:ListItem Text=""></asp:ListItem> "
0
Princy
Top achievements
Rank 2
answered on 26 Nov 2009, 06:59 AM
Hello Pradeep,
Rather than setting an empty ListItem in the dropdownlist, another suggestion would be to preset a value in the dropdownlist while the grid is in insert mode, inorder to avoid the error:
c#:
Hope this helps.
-Princy.
Rather than setting an empty ListItem in the dropdownlist, another suggestion would be to preset a value in the dropdownlist while the grid is in insert mode, inorder to avoid the error:
c#:
| protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| if (e.CommandName == RadGrid.InitInsertCommandName) |
| { |
| //Add new" button clicked |
| e.Canceled = true; |
| //Prepare an IDictionary with the predefined values |
| System.Collections.Specialized.ListDictionary newValues = new |
| System.Collections.Specialized.ListDictionary(); |
| newValues["Status"] = "Open"; |
| //Insert the item and rebind |
| e.Item.OwnerTableView.InsertItem(newValues); |
| } |
| } |
Hope this helps.
-Princy.
0
pradeep k
Top achievements
Rank 1
answered on 26 Nov 2009, 07:27 AM
Thank U.
0
pradeep k
Top achievements
Rank 1
answered on 26 Nov 2009, 07:54 AM
I have one more issue,
I have a dropdown column called "Year" in grid.
in edit mode i am setting readonly property to true for this column, but in insert mode i want to add the years to dropdown from database table, how can i do this in RadGrid1_ItemCommand event .
Please help me regarding this.
I have a dropdown column called "Year" in grid.
in edit mode i am setting readonly property to true for this column, but in insert mode i want to add the years to dropdown from database table, how can i do this in RadGrid1_ItemCommand event .
Please help me regarding this.
0
Shinu
Top achievements
Rank 2
answered on 26 Nov 2009, 11:19 AM
Hi Pradeep,
To disable editing and allow only inserting for the dropdowncolumn, you have to set the ReadOnly property of the column accordingly based on the commands. Here's how you can achieve it:
c#:
| protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| foreach (GridColumn col in RadGrid1.Columns) |
| { |
| if (col.ColumnType == "GridDropDownColumn" && col.UniqueName == "DropDownColumnUniqueName") |
| { |
| if (e.CommandName == RadGrid.EditCommandName) |
| { |
| (col as GridDropDownColumn).ReadOnly = true; |
| col.Visible = false; |
| } |
| else |
| { |
| (col as GridDropDownColumn).ReadOnly = false; |
| col.Visible = true; |
| } |
| } |
| } |
| } |
And to populate the combobox in Insertmode, you can try out the following code :
c#:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted) |
| { |
| GridDataInsertItem insertItem = (GridDataInsertItem)e.Item; |
| RadComboBox combo = (RadComboBox)insertItem["Dropdown"].Controls[0]; |
| combo.DataSource = dt; |
| combo.DataTextField = "Years"; |
| combo.DataValueField = "Years"; |
| combo.DataBind(); |
| } |
| } |
Hope this helps..
Shinu.
0
pradeep k
Top achievements
Rank 1
answered on 26 Nov 2009, 12:25 PM
I did what you said,
it is not entering in to condition if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted)
Please let me know what to do.
it is not entering in to condition if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted)
Please let me know what to do.