I currently have a grid that is always in editmode. The first column has a dropdown box with 2 entries and depending on which item you choose in the dropdown depends on what the datasource is for the dropdown in column 2. When executing this code I'm receiving an error that says....
"Cannot have multiple items selected in a DropDownList."
Also I'm trying to figure out how to attache an procedure to the selectedindexchange of the first dropdown but it's currenlty not working
Any help would be appreciated.
Here is a copy of the code.
"Cannot have multiple items selected in a DropDownList."
Also I'm trying to figure out how to attache an procedure to the selectedindexchange of the first dropdown but it's currenlty not working
Any help would be appreciated.
Here is a copy of the code.
protected void rdPaymentsLines_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) { try { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem editedItem = e.Item as GridDataItem; GridEditManager editMan = editedItem.EditManager; GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ESCROW_CATEGORY")); GridDropDownListColumnEditor escrowType = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ESCROW_TYPE")); DropDownList ddEscrowCategory = editor.DropDownListControl; DropDownList ddEscrowType = escrowType.DropDownListControl; ddEscrowCategory.Items.Insert(0, new ListItem("Ins", "INSURANCE")); ddEscrowCategory.Items.Insert(1, new ListItem("Tax", "TAX")); editor.DataBind(); ddEscrowCategory.SelectedIndexChanged += new EventHandler(ddEscrowList_SelectedIndexChanged); if (ddEscrowCategory.SelectedItem.Text == "Tax") escrowType.DataSource = Session["TaxTypeList"]; else escrowType.DataSource = Session["InsuranceList"]; escrowType.DataBind(); 5 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 07 Dec 2010, 11:03 AM
Hello,
Make the following modification in your code and check if it works. Also check whether you have set DropDownControlType as 'DropDownList' in GridDropDownColumn.
C#:
Thanks,
Princy.
Make the following modification in your code and check if it works. Also check whether you have set DropDownControlType as 'DropDownList' in GridDropDownColumn.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem editedItem = e.Item as GridEditableItem; GridEditManager editMan = editedItem.EditManager; GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ESCROW_CATEGORY")); GridDropDownListColumnEditor escrowType = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ESCROW_TYPE")); DropDownList ddEscrowCategory = editor.DropDownListControl; DropDownList ddEscrowType = escrowType.DropDownListControl; ddEscrowCategory.Items.Insert(0, new ListItem("Ins", "INSURANCE")); ddEscrowCategory.Items.Insert(1, new ListItem("Tax", "TAX")); editor.DataBind(); ddEscrowCategory.AutoPostBack = true; ddEscrowCategory.SelectedIndexChanged += new EventHandler(ddEscrowCategory_SelectedIndexChanged); } } void ddEscrowCategory_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddEscrowCategory = (DropDownList)sender; GridEditableItem editedItem = (GridEditableItem)ddEscrowCategory.NamingContainer; DropDownList escrowType = (DropDownList)editedItem["GridDropDownColumn2"].Controls[0]; if (ddEscrowCategory.SelectedItem.Text == "Tax") escrowType.DataSource = Session["TaxTypeList"]; else escrowType.DataSource = Session["InsuranceList"]; escrowType.DataBind(); }Thanks,
Princy.
0
New User
Top achievements
Rank 1
answered on 07 Dec 2010, 04:59 PM
Thanks for help I'm almost there.
1. It doesn't seem to work on the item if it is inserted mode.
2. Already completed records do not seem to be set to the correct item. ie(Grid item is set to "Flood" the dropdown list shows "Homeowners" which it the first item in the grid)
3. The second dropdown does not populate for existing items.
1. It doesn't seem to work on the item if it is inserted mode.
2. Already completed records do not seem to be set to the correct item. ie(Grid item is set to "Flood" the dropdown list shows "Homeowners" which it the first item in the grid)
3. The second dropdown does not populate for existing items.
0
Princy
Top achievements
Rank 2
answered on 08 Dec 2010, 12:50 PM
Hello,
I guess you are using RadGrid EditMode as 'EditForms'. If so in ItemCreated event you need to check whether the item is in insert mode and attach 'SelectedIndexChanged' event for DropDownList.
C#:
And give a try with the following code snippet to select the correct value in DropDownList corresponding to the grid row.
C#:
Thanks,
Princy.
I guess you are using RadGrid EditMode as 'EditForms'. If so in ItemCreated event you need to check whether the item is in insert mode and attach 'SelectedIndexChanged' event for DropDownList.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) // checking if the item is in insert mode { GridEditFormInsertItem insertItem = e.Item as GridEditFormInsertItem; GridEditManager editMan = insertItem.EditManager; GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("GridDropDownColumn1")); DropDownList ddEscrowCategory = editor.DropDownListControl; ddEscrowCategory.AutoPostBack = true; ddEscrowCategory.SelectedIndexChanged += new EventHandler(ddEscrowCategory_SelectedIndexChanged); } }And give a try with the following code snippet to select the correct value in DropDownList corresponding to the grid row.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormItem && e.Item.IsInEditMode)// checking if the item is in edit mode { GridEditFormItem editItem = e.Item as GridEditFormItem ; GridEditManager editMan = editItem .EditManager; GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("GridDropDownColumn1")); DropDownList ddEscrowCategory = editor.DropDownListControl; DataRowView rowview = (DataRowView)insertItem.DataItem; ddEscrowCategory.SelectedValue = rowview["FieldName"].ToString();//access corresponding value using your database 'fieldname' } }Thanks,
Princy.
0
New User
Top achievements
Rank 1
answered on 09 Dec 2010, 04:23 AM
Ok Getting There I'm having a problem getting the dropdown to default to the value from the row. I've pasted in my entire code and hope that someone can help.
I'm trying to get the dropdown Escrow_Type to show the correct item in the dropdown from the row.
Any Help would be great.
protected void rdPaymentsLines_ItemDataBound(object sender, GridItemEventArgs e) { try { if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) { GridEditableItem editedItem = e.Item as GridEditableItem; TableCell expectedCell = editedItem["EXPECTED_TRANSACTION_IND"]; //access cell using ColumnUniqueName string EXPECTED_TRANSACTION_IND = (expectedCell.Controls[0] as TextBox).Text;// get id DropDownList ddEscrowList = (DropDownList)editedItem["ESCROW_CATEGORY"].Controls[0]; DropDownList ddTypeList = (DropDownList)editedItem["ESCROW_TYPE"].Controls[0]; GridEditableItem editItem = (GridEditableItem)ddEscrowList.NamingContainer; DropDownList drlist = (DropDownList)editItem.FindControl("LenderPayeeCode"); RadTextBox txtbox = (RadTextBox)editItem.FindControl("PayeeName"); if (ddEscrowList.SelectedValue == "TAX") { txtbox.Visible = false; drlist.Visible = true; } else { drlist.Visible = false; txtbox.Visible = true; } if (EXPECTED_TRANSACTION_IND == "YES") { if (ddEscrowList.SelectedValue == "TAX") drlist.Enabled = false; else txtbox.Visible = false; editedItem["Delete"].Controls[0].Visible = false; ddEscrowList.Enabled = false; ddTypeList.Enabled = false; } else { if (ddEscrowList.SelectedValue == "TAX") drlist.Enabled = true; else txtbox.Visible = true; (editedItem["Delete"].Controls[0] as ImageButton).ImageUrl = "~/Images/deleteX.gif"; ddEscrowList.Enabled = true; ddTypeList.Enabled = true; } GridEditManager editMan = editedItem.EditManager; GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ESCROW_CATEGORY")); GridDropDownListColumnEditor escrowType = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("ESCROW_TYPE")); DropDownList ddEscrowCategory = editor.DropDownListControl; DropDownList ddEscrowType = escrowType.DropDownListControl; if (ddEscrowCategory.SelectedItem.Text == "Tax") escrowType.DataSource = Session["TaxTypeList"]; else escrowType.DataSource = Session["InsuranceList"]; escrowType.DataBind(); DataRowView rowview = (DataRowView)editedItem.DataItem; escrowType.SelectedValue = rowview["ESCROW_TYPE"].ToString(); } if (e.Item is GridCommandItem) { Button addTransaction = (Button)e.Item.FindControl("btnAdd"); if (addTransaction != null) addTransaction.Focus(); } } catch (Exception ex) { ToolSet.LogEvent("Exception in rdPaymentsLines_ItemDataBound method: " + ex.Message, ToolSet.LogEventLevel.Error); throw; } }void ddEscrowCategory_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddEscrowCategory = (DropDownList)sender; GridDataItem editedItem = (GridDataItem)ddEscrowCategory.NamingContainer; DropDownList escrowType = (DropDownList)editedItem["ESCROW_TYPE"].Controls[0]; DropDownList drlist = (DropDownList)editedItem.FindControl("LenderPayeeCode"); RadTextBox txtbox = (RadTextBox)editedItem.FindControl("PayeeName"); if (ddEscrowCategory.SelectedItem.Text == "Tax") { escrowType.DataSource = Session["TaxTypeList"]; drlist.Visible = true; txtbox.Visible = false; } else { escrowType.DataSource = Session["InsuranceList"]; drlist.Visible = false; txtbox.Visible = true; } escrowType.DataBind(); if (ddEscrowCategory.SelectedItem.Text == "Tax") { DataTable LppList = DBEscrowServicing.GetLpps(Session["CurrentLender"].ToString(), loanData.PropertyState, "312"); if (LppList.Rows.Count > 0) { drlist.DataSource = LppList; drlist.DataTextField = "LENDER_PAYEE_NAME"; drlist.DataValueField = "LENDER_PAYEE_CODE"; drlist.DataBind(); } } } I'm trying to get the dropdown Escrow_Type to show the correct item in the dropdown from the row.
Any Help would be great.
0
Princy
Top achievements
Rank 2
answered on 09 Dec 2010, 12:18 PM
Hello,
Check whether you have set the ListTextField and ListValueField properties of DropDownColumn. Try to set it and see if it works now.
ASPX:
Thanks,
Princy.
Check whether you have set the ListTextField and ListValueField properties of DropDownColumn. Try to set it and see if it works now.
ASPX:
<telerik:GridDropDownColumn ListTextField="ESCROW_TYPE" ListValueField="ESCROW_TYPE" DropDownControlType="DropDownList" UniqueName="ESCROW_TYPE"></telerik:GridDropDownColumn>Thanks,
Princy.