views:

572

answers:

4

Is there a way to handle the DropDownSelectedIndexChanged for list item new form.

Let say I have a custom list named Temp having Title, Products (which is a DropDownList) and Color Shade (which is a TextBox). When I create a list item I want to select a product from DropDownList and on the selected index changed I want to write the business logic such as fetching the row from Color Shade list and bind the data to TextBox of Color Shade. Now I can say ok so that a list item will be created. Is it possible using VS 2008 sharepoint object model.

A: 

you could add a custom control to your masterpage which resursively traverses your control tree (start from this.Page) to find your dropdown and attaches the event handler (which itself is defined in your custom control). Also set the AutoPostBack property to true on the dropdown once you found it.

In terms of getting a reference do your textbox within your eventhandler, you could also apply the same approach of traversing the control tree.

note, you need to ensure that event handler is attached before eventhandlers are run.

Jaap

Jaap
A: 

Hi Jaap,

Thanks for reply. But what if I want to use other out of box features of List i.e. Instead of having our own web part or custom control. Is it possible to use the out of box feature?. Like the New menu then Acion Menu e.t.c. Are u getting my point?...

Thanks & Regards, Tejas Jagtap

A: 

Hi Tejas,

I am not sure if I understand what you mean.

An alternative approach, and probably less work, would be to use javascript (I would recommend using the jQuery library) to automatically populate your textbox when the selection of the dropdown changes. Everything would be done clientside.

Jaap

Jaap
A: 

There are some third party components that do this sort of thing as custom column types, but if you're developing from scratch you'll probably find it a lot easier doing a custom form. If you do a fully custom version of newform.aspx, you'll still be using the standard new item menu.

If you try to modify the standard controls you'll run into issues like security errors if the submitted value wasn't in the original list.

If you don't want to write your own saving code, hiding the standard new form with css and modifying the values with javascript from your custom control can work quite well.

Tom Clarkson