I have in a GridView control a TemplateField like:
<asp:TemplateField ItemStyle-Width="150px">
<ItemTemplate>
<asp:DropDownList ID="ddlFields" runat="server" DataSourceID="odsOperator" DataTextField="Text" DataValueField="Value" />
<asp:HiddenField ID="hfFieldType" runat="server" Value='<%# Eval("FieldType")%>' />
</ItemTemplate>
</asp:TemplateField>
I have a dropdown that I want to populate from a ObjectDataSource, but for each line I want to pass a Select Parameter so it populates with the right values
<asp:ObjectDataSource ID="odsOperator" runat="server" TypeName="OperatorFieldsDAO"
SelectMethod="FindByType">
<SelectParameters>
<asp:ControlParameter ControlID="hfFieldType" Type="String" Name="Type" PropertyName="Value" />
</SelectParameters>
</asp:ObjectDataSource>
my OperatorFieldsDAO class is:
public class OperatorFieldsDAO
{
private List<OperatorField> OperatorFields
{
get
{
List<OperatorField> operatorFields = HttpContext.Current.Session["OperatorFields"] as List<OperatorField>;
if (operatorFields == null)
{
operatorFields = new List<OperatorField>();
operatorFields.Add(new OperatorField("string", "contains", "C"));
operatorFields.Add(new OperatorField("string", "begins with", "BW"));
operatorFields.Add(new OperatorField("string", "is equal to", "E"));
operatorFields.Add(new OperatorField("string", "is not equal to", "NE"));
operatorFields.Add(new OperatorField("string", "is less than", "L"));
operatorFields.Add(new OperatorField("string", "is greater than", "G"));
operatorFields.Add(new OperatorField("string", "is less than or equal to", "LE"));
operatorFields.Add(new OperatorField("string", "is greater than or equal to", "GE"));
operatorFields.Add(new OperatorField("string", "is from", "F"));
operatorFields.Add(new OperatorField("string", "is between", "B"));
operatorFields.Add(new OperatorField("string", "is nothing", "N"));
operatorFields.Add(new OperatorField("string", "is something", "S"));
operatorFields.Add(new OperatorField("number", "is the same as", "S"));
operatorFields.Add(new OperatorField("number", "is not the same as", "S"));
operatorFields.Add(new OperatorField("number", "is one of", "S"));
operatorFields.Add(new OperatorField("number", "is not one of", "S"));
operatorFields.Add(new OperatorField("number", "is nothing", "N"));
operatorFields.Add(new OperatorField("number", "is something", "S"));
}
return operatorFields;
}
}
public OperatorFieldsDAO() { }
[DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable<OperatorField> FindAll()
{
return this.OperatorFields;
}
[DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable<OperatorField> FindByType(String type)
{
List<OperatorField> r = new List<OperatorField>();
foreach (OperatorField f in this.OperatorFields)
if (f.Type == type)
r.Add(f);
return r;
}
}
all of this to tell you that I get an error:
Could not find control 'hfFieldType' in ControlParameter 'Type'.
What am I doing wrong?
Do I need to programatically pass that selected parameter using the OnRowDataBound method?