I have a CascadingDropDown inside of an GridView EditItemTemplate. Code is below. I need the SelectedValue of the CascadingDropDown to come from the database when then user Edit's the row. I tried addingSelectedValue='<%# Bind("sentity") %>' but I get this error:
Parser Error Message:The CascadingDropDownProperties control with a two-way databinding to field sentity must have an ID.
Source Error:
Line 67: Line 68: <atlasToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server">Line 69: <atlasToolkit:CascadingDropDownPropertiesLine 70: TargetControlID="ddlEditEntity" Line 71: Category="Entity"
<asp:TemplateFieldHeaderText="Entity">
<EditItemTemplate><asp:DropDownListID="ddlEditEntity"runat="server"CssClass="dropDownList"/><atlasToolkit:CascadingDropDownID="CascadingDropDown2"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditEntity"Category="Entity"PromptText="<-- Selected an Entity -->"ServicePath="webservices/ws_Timetracking.asmx"ServiceMethod="GetEntitesText"SelectedValue='<%# Bind("sentity") %>'/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditProperty"ParentControlID="ddlEditEntity"PromptText="<-- Select a Property -->"ServiceMethod="GetPropsForEntitytext"ServicePath="webservices/ws_Timetracking.asmx"Category="Property"/></atlasToolkit:CascadingDropDown></EditItemTemplate><ItemStyleHorizontalAlign="Left"Width="20%"/><HeaderStyleHorizontalAlign="Left"/><ItemTemplate><asp:LabelID="lblEntity"runat="server"Text='<%# Bind("sentity") %>'></asp:Label></ItemTemplate></asp:TemplateField>As you've noted, the Toolkit controls don't support data binding yet. (Though we have plans to do so soon!) For the time being, I believe you can override your page's OnDataBind method and set the SelectedValue in code. I think Shawn's posted an example of this to the forum. If that's not enough to get you going, reply back and I'll post a sample.David, I tried setting the selectedValue for the dropdownlist in theGridView1_RowUpdating method, but it seems to not be working.
GridViewRow row = GridView1.Rows[e.RowIndex];DataKey datakey = GridView1.DataKeys[e.RowIndex];
// Get hmy for updating the database
int hmy =Convert.ToInt32(datakey.Value.ToString());
if (row !=null)
{
DropDownList ddlEditEntity = row.FindControl("ddlEditEntity")asDropDownList;
DropDownList ddlEditProperty = row.FindControl("ddlEditProperty")asDropDownList;
TextBox txtEditDescription = row.FindControl("txtEditDescription")asTextBox;
TextBox txtEditHours = row.FindControl("txtEditHours")asTextBox;ddlEditEntity.SelectedValue = "Chastain Center (8755)"; // this doesn't seem to be workingstring entity = ddlEditEntity.SelectedItem.Value;string property = ddlEditProperty.SelectedItem.Value;string description = txtEditDescription.Text;decimal hours =Convert.ToDecimal(txtEditHours.Text);int retval =Queries.UpdateEntity(hmy, entity, property, description, hours);
GridView1.EditIndex = -1;
GetTimeByUser(ddlYear.SelectedValue +
"/" + ddlMonth.SelectedValue);}
Well, we added databinding support in the 60731 release of the Toolkit. :) Would you mind trying that approach again with the updated Toolkit? Failing that, let me know and I'll have a look. For real this time. :) Thanks!
When upgrading to the latest do all I need to do is swap out the dll, correct?
Yes, but you'll need to swap out the Microsoft.Web.Atlas.DLL as well (if you're not already using the July CTP).
Thanks David I will try this approach today. One final question. Is it necessary to swap out the Script Library as well? Do you guys update the JavaScript code to reflect changes in the dll?
I swapped out my dll's as followed:
AtlasControlToolkit.dll (version 1.0.60731.0)
Microsoft.AtlasControlExtender.dll (version 1.0.60726.0)
Microsoft.Web.Atlas.dll (version 2.0.50727.60725)
And did the following and still get the error:
The CascadingDropDownProperties control with a two-way databinding to field sentity must have an ID.
<asp:TemplateFieldHeaderText="Entity"><EditItemTemplate><asp:HiddenFieldID="hdnEditEntity"runat="server"Value='<%# Bind("sentity") %>'/><asp:DropDownListID="ddlEditEntity"runat="server"CssClass="dropDownList"/><atlasToolkit:CascadingDropDownID="CascadingDropDown2"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditEntity"SelectedValue='<%# Bind("sentity") %>'
Category="Entity"PromptText="<-- Selected an Entity -->"ServicePath="webservices/ws_Timetracking.asmx"ServiceMethod="GetEntitesText"/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditProperty"ParentControlID="ddlEditEntity"PromptText="<-- Select a Property -->"ServiceMethod="GetPropsForEntitytext"ServicePath="webservices/ws_Timetracking.asmx"Category="Property"/></atlasToolkit:CascadingDropDown></EditItemTemplate>joee, I've looked into this for some time and discussed the issue with Shawn as well. Unfortunately for your scenario, we're only able to use one-way databinding (i.e., Eval) in Extender Properties declarations. If you want to handle the CascadingDropDown's SelectedValue that comes back from the client, you'll need to do so in code (at least for the time being - fortunately it shouldn't be very much code!). At a very high level, in order to support two-way databinding, ASP.NET looks for a real Control (hence the error you get about needing an ID) and the Extender Properties objects aren't currently Controls themselves.
Sorry for the trouble; I hope this explanation at least makes things clearer.
Hello
I have a CascadingDropDown in a page and need to set its selectedValue based on the values in the querystring. I tried to use the DataBinding event to set the values, but looks like the event is not being raised.
protected void CascadingDropDown1_DataBinding(object sender, EventArgs e)
{
ddMake.SelectedValue = Request.QueryString["make"];
ddModel.SelectedValue = Request.QueryString["model"];
}
Any ideas?
Thanks for the report! I've just fixed this problem for the next Toolkit release with change 3420 in CodePlex:
Method override ExtenderControlBase.OnDataBinding didn't call base.OnDataBinding, so event handlers hooked up to an extender's .DataBinding event weren't getting fired - this change fixes that problem by calling the base class implementation as it should.
If you're able to use the sources from CodePlex, this should work now. Sorry for the trouble!
Thanks David. I guess change 3431 will address my issue as well. Pardon my ignorance, but how do I work off the source code? Do I just need to build and swap out the Web.Atlas and AtlasControlToolkit.dll?
Yes, just download the sources from CodePlex, extract the files somewhere, build the project, and then use the resulting AtlasControlToolkit.dll instead of the one you were formerly using.
So what is the status now regarding to ways binding, e.g. binding a dropdown's selectedvalue to an item in detailsview ?
No comments:
Post a Comment