Hello, I have a RadGrid with an EditFormType set to 'Template'. I can't figure out how to access form elements inside this FormTemplate from the code behind. I'm trying to make one drop down change its options when another one is selected.
When I try to compile this code, it tells me "The name 'drpEditTarget' does not exists in the current context.". If I move that drop-down outside of the RadGrid, it's suddenly accessible again. I guess my two questions are...
--1) How can I access this element from the code behind?
--2) What's the difference between elements outside and inside the Grid? Why can I access the former but not the latter? (the answer to this might be a more broad asp.net question)
Default.aspx
<
Telerik:RadGrid
ID
=
"RequestsGrid"
runat
=
"server"
OnNeedDataSource
=
"RequestsGrid_NeedDataSource"
OnCancelCommand
=
"RequestGrid_CancelCommand"
OnDeleteCommand
=
"RequestsGrid_DeleteCommand"
OnItemCommand
=
"RequestGrid_ItemCommand"
OnItemDataBound
=
"RequestsGrid_ItemDataBound"
AllowAutomaticDeletes
=
"false"
AllowAutomaticInserts
=
"false"
AllowAutomaticUpdates
=
"true"
DataSourceID
=
"requests"
>
<
MasterTableView
AutoGenerateColumns
=
"false"
DataKeyNames
=
"id,requester,output,notes"
DataSourceID
=
"requests"
CommandItemDisplay
=
"Bottom"
>
<
EditFormSettings
EditFormType
=
"Template"
>
<
EditColumn
UniqueName
=
"EditColumn"
></
EditColumn
>
<
FormTemplate
>
<
b
>First Target:</
b
>
<
asp:DropDownList
runat
=
"server"
SelectedValue='<%# Eval("target") %>' ID="drpEditTarget" AutoPostBack="true" DataSource='<%# getPossibleTargets( (string)Eval("output") ) %>' OnSelectedIndexChanged="drpEditTarget_SelectedIndexChanged"></
asp:DropDownList
>
<
b
>Second Target:</
b
></
td
>
<
asp:DropDownList
runat
=
"server"
ID
=
"drpEditSecondTarget"
></
asp:DropDownList
>
<
asp:Button
ID
=
"btnUpdate"
CommandName
=
"Update"
Text
=
"Update"
runat
=
"server"
/>
<
asp:Button
ID
=
"btnCancel"
CommandName
=
"Cancel"
Text
=
"Cancel"
runat
=
"server"
/>
</
FormTemplate
>
</
EditFormSettings
>
<
Columns
>
<
telerik:GridEditCommandColumn
UniqueName
=
"EditButton"
Visible
=
"false"
ItemStyle-CssClass
=
"skinny"
/>
<
telerik:GridButtonColumn
Text
=
"Delete"
UniqueName
=
"DeleteButton"
CommandName
=
"Delete"
></
telerik:GridButtonColumn
>
<
telerik:GridBoundColumn
DataField
=
"id"
HeaderText
=
"ID"
UniqueName
=
"id"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"requester"
HeaderText
=
"Requester"
UniqueName
=
"requester"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"output"
HeaderText
=
"Output"
UniqueName
=
"output"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"notes"
HeaderText
=
"Notes"
UniqueName
=
"notes"
></
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
Text
=
"Approve"
UniqueName
=
"ApproveButton"
CommandName
=
"Approve"
></
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
Text
=
"Deny"
UniqueName
=
"DenyButton"
CommandName
=
"Deny"
></
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
</
Telerik:RadGrid
>
Default.aspx.cs
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
populateGrid();
if
(!Page.IsPostBack)
{
setFilterOptions();
RequestsGrid.Rebind();
}
}
protected
void
drpEditTarget_SelectedIndexChanged(
object
sender, EventArgs e)
{
drpEditSecondTarget.DataSource = getPossibleDestinations( drpEditTarget.SelectedValue.ToString() );
drpEditSecondTarget.DataBind();
}
}