views:

479

answers:

2

I am using a RadGrid to display data gathered from various xml files. I have defined an EditFormTemplate where additional data can be seen/edited. Now whenever I add controls into this template, the designer doesn't add the necessary control to the designer.cs codebehind file. Why?

Edit: Most specifically, I have a asp:DropDownList that I want to initialize with a preselected value. I've tried doing this in the PageLoad of the CodeBehind, and even in a separate EventHandler that I bound to onInit and onLoad of the control. Both of these get called, but the control "doesn't seem to exist" for the codebehind.

I used FindControl, and cast the result to a DropDownList object, but this seems to return null.

A: 

Is this a web site (created with File->New Web Site) or a Web Application Project (created with File->New Project)? In a web site, there is nothing added to the partial class file. It's all built by magic at runtime.

Does the grid not display when you open the page in a browser?

John Saunders
It is a project, and the RadGrid does get added to the partial class file. I can access the RadGrid in the CodeBehind.Also, the grid shows up, and displays the data.
I'm awake now. You're talking about controls in a template. The template is only instantiated at runtime. It's not meant that the controls should ever exist in any source file. Try this with a simple Repeater control, and you'll see the same thing.
John Saunders
Good morning :) So this solves my question, but of course means I still can't have a preselected value for the DropDownList. There must be another way though, right?
A: 

Preselecting a value for a DropDownList is done like this:
<asp:DropDownList SelectedValue='<%# Bind("codeBehindVariable") %>' runat="server" ID="id" />
I just wonder why I missed this property of asp:dropdownlist when i was looking for a solution.