This is a migrated thread and some comments may be shown as answers.

SelectedIndexChanged Event on dropdown results in closing Edit mode

3 Answers 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pbreck
Top achievements
Rank 1
pbreck asked on 18 Mar 2010, 04:01 PM
I need to hide some input cols when the value changes in a a dropdownlist in edit mode.  I added a SelectedIndexChanged event in the Item_Created for the dropdownlist.   The event fires when I change the dropdown but then it leaves edit mode.   I think the issue is I have to set the autopostBack to true on the list, but if I don't set it to true it won't fire when I change the value in the list.  

Is there another way to implement this?

 

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)

 

{

 

if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "DeviceDetail")

 

{

 

//the dropdown list will be the first control in the Controls collection of the corresponding cell

 

 

 

 

 

 

DropDownList list = (e.Item as GridEditableItem)["DeviceTypeDropDown"].Controls[0] as DropDownList;

 

 

list.AutoPostBack =

true;

 

list.SelectedIndexChanged +=

new EventHandler(DeviceTypeIndex_Changed);

 

}

 

void

 

 DeviceTypeIndex_Changed(Object sender, EventArgs e)

 

{

 

    DropDownList list = sender as DropDownList;

 

 

    GridEditableItem editedItem = (sender as DropDownList).NamingContainer as GridEditableItem;

 

 

    if (((DropDownList)sender).SelectedItem.Text == "Device1")

 

    {

        editedItem[

"isDeviceAdjacent"].Controls[0].Visible = true;

 

    }

 

    else

 

 

 

    {

 

        editedItem[

"isDeviceAdjacent"].Controls[0].Visible = false;

 

    }

}

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 18 Mar 2010, 04:23 PM
Hi pbreck,

If you do not rebind the grid explicitly when you change the selected item in the combobox, you should be able to hide controls in cells from the same row without leaving the edit mode.

In support of my statement I am directing you to an online example which utilizes similar approach to modify the state of controls inside RadGrid's edit form on combo item selection:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx

Kind regards,
Sebastian
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
pbreck
Top achievements
Rank 1
answered on 18 Mar 2010, 06:28 PM

I think I found my issue. (Had some code in prerender which collapsed the open row.  It was firing now since I had the postback when previously it didn't fire till I hit updated).   

The field I was trying to not make visible goes away but the label still remains.  Is there a way to programatically to hide that?  

 

editedItem[

"isDeviceAdjacent"].Controls[0].Visible = false;

Device Adjacent : 

I want to get rid of the "Device Adjacent"  which comes from col header.  Also want to remove the colon ":".  

I basically need to remove this col from edit screen when the dropdown has any value but device1. 

Also I have another situation where I change the header of the col to be " " and made the textbox not visible but the Colon (:) still shows.  Is there a way to remove that programatically. 

I'm letting radgrid build the edit row dynamically.  Have editmode set to "editforms"

 

0
Sebastian
Telerik team
answered on 19 Mar 2010, 10:42 AM
Hi pbreck,

To remove the label text and the colon when hiding the column editor, consider setting the EditFormHeaderTextFormat property of the respective column to an empty string. Keep in mind that you will need to rebind the grid explicitly to reflect the changes.

Alternatively, consider replacing the auto-generated edit form with FormTemplate or WebUserControl custom edit form which gives you greater flexibility over the edit form structure and editors. Thus you will be able to design it in par with your preferences and locate the labels/editors by their id using the FindControl(id) method.

Kind regards,
Sebastian
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
pbreck
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
pbreck
Top achievements
Rank 1
Share this question
or