Hi guys,
Having an issue databinding with an Edit in Place grid, when one dropdown's values need to update on postback from the SelectedIndexChanged of another.
I'll put in some of the code at the bottom, I can post more if need be. (This is a client's code base I'm working with, so I've scrubbed contextual info. Please forgive typos or generic-ness in the code!)
Here's the summary:
I'm using LinqDataSources to populate dropdown1 & dropdown2. Originally they were each GridDropDownColumns, all was great. Then, I found out a requirement that the second dropdown needs to be filtered by a foreign key in the db based on on the selection of dropdown1.
So, I changed both columns to a GridTemplateColumn, no prob. I found references to http://www.telerik.com/help/aspnet-ajax/grid-with-combobox.html which discusses the first part. The binding works fine without any autopostbacks on the dropdown1.
Then I added a SelectedIndexChanged as pasted below - works great, the selected value of dropdown1 is maintained in my private int, and the LinqDataSources gets the correct enumeration back.
However, with the (SelectedValue='<%#Bind("Value2") %>') on dropdown2, when the post back occurs, I get an error:
I found this (http://www.telerik.com/community/forums/aspnet-ajax/grid/databinding-methods-such-as-eval-xpath-and-bind-can-only-be-used-in-the-context-of-a-databound-control.aspx) and a few others saying the same, but that solution doesn't bind on save.
I've seen a post (I think reference on this forum) to a nested set of dropdowns, but that example was where only the second of the two dropdown values needed to be stored. Both values here are needed, so I don't believe I can place both dropdowns in the same column & manipulate.
I also tried decoupling the binding. I was able to populate the dropdown2 on the RadGrid1_ItemDataBound, and I could even get the update save bound by using the LinqDataSource's Updating event and hitting the dropdown2 using the RadGrid's EditItems. However, I'm unable to get the dropdown2's value on the LDS's Insert to modify the saved object. Doesn't feel like the right solution, but it almost worked. I couldn't figure out how to save/modify my data object on insert & update using the ItemInserted/ItemUpdated events.
Any help would be appreciated!
Having an issue databinding with an Edit in Place grid, when one dropdown's values need to update on postback from the SelectedIndexChanged of another.
I'll put in some of the code at the bottom, I can post more if need be. (This is a client's code base I'm working with, so I've scrubbed contextual info. Please forgive typos or generic-ness in the code!)
Here's the summary:
I'm using LinqDataSources to populate dropdown1 & dropdown2. Originally they were each GridDropDownColumns, all was great. Then, I found out a requirement that the second dropdown needs to be filtered by a foreign key in the db based on on the selection of dropdown1.
So, I changed both columns to a GridTemplateColumn, no prob. I found references to http://www.telerik.com/help/aspnet-ajax/grid-with-combobox.html which discusses the first part. The binding works fine without any autopostbacks on the dropdown1.
Then I added a SelectedIndexChanged as pasted below - works great, the selected value of dropdown1 is maintained in my private int, and the LinqDataSources gets the correct enumeration back.
However, with the (SelectedValue='<%#Bind("Value2") %>') on dropdown2, when the post back occurs, I get an error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
I found this (http://www.telerik.com/community/forums/aspnet-ajax/grid/databinding-methods-such-as-eval-xpath-and-bind-can-only-be-used-in-the-context-of-a-databound-control.aspx) and a few others saying the same, but that solution doesn't bind on save.
I've seen a post (I think reference on this forum) to a nested set of dropdowns, but that example was where only the second of the two dropdown values needed to be stored. Both values here are needed, so I don't believe I can place both dropdowns in the same column & manipulate.
I also tried decoupling the binding. I was able to populate the dropdown2 on the RadGrid1_ItemDataBound, and I could even get the update save bound by using the LinqDataSource's Updating event and hitting the dropdown2 using the RadGrid's EditItems. However, I'm unable to get the dropdown2's value on the LDS's Insert to modify the saved object. Doesn't feel like the right solution, but it almost worked. I couldn't figure out how to save/modify my data object on insert & update using the ItemInserted/ItemUpdated events.
Any help would be appreciated!
<
telerik:GridTemplateColumn
UniqueName
=
"Column1"
HeaderText
=
"Insurance"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblColumn1"
runat
=
"server"
Text= '<%# ((MyObject)Container.DataItem).Value1 %> '></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"RcbDropdown1"
DataTextField
=
"Table1Name"
DataValueField
=
"Table1ID"
DataSourceID
=
"ldsTable1"
NoWrap
=
"True"
SelectedValue='<%#Bind("Value1") %>' OnSelectedIndexChanged="RcbDropdown1_SelectedIndexChanged" AutoPostBack="True" OnDataBound="RcbDropdown1_DataBound" >
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"Column2"
HeaderText
=
"Insurance Payer"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblColumn2"
runat
=
"server"
Text= '<%# ((MyObject)Container.DataItem).Value2 %> '></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"RcbDropdown2"
DataTextField
=
"Table2Name"
DataValueField
=
"Table2ID"
DataSourceID
=
"ldsTable2"
SelectedValue='<%#Bind("Value2") %>' OnDataBound="RcbDropdown1_DataBound" OnDataBinding="RcbDropdown1_DataBinding">
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
private int myvalue1 { get; set; }
protected void RcbDropdown1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
myvalue1 = Maybe.ToInt32(e.Value);
var dropdown1 = (RadComboBox)sender;
var item = (GridEditableItem)rcb.NamingContainer;
var dropdown2 = (RadComboBox)item.FindControl("RcbDropdown2");
if (dropdown2 != null)
{
dropdown2.DataSourceID = "ldsTable2";
dropdown2.DataTextField = "Table2Name";
dropdown2.DataValueField = "Table2ID";
dropdown2.DataBind();
}
}
protected void ldsTable2_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
var results = new List<
MySecondObject
>();
if (myvalue1.HasValue)
{
results = {Repo Call with Enumeration Results filtering by myvalue1}
}
e.Result = results;
}