T
tfsmag
I have a Grid that I've set up to have two of the fields use
dropdownlists while in edit mode. Now I can bind the data to the
dropdownlists just fine. My problem is that the second dropdown depends
on the first dropdown to pass a parameter to it. If I have a
selectedvalue set to the second drop down, when i select a new value
from the first drop down it gives me this error.
"Databinding methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."
After searching around for nearly a whole day, I have tried a million
things, including something like what was done here
http://www.webswapp.com/CodeSamples/viewsource.aspx?file=\aspnet20\FormView1.aspx
summary: The first dropdown has autopostback set to true, on
autopostback it feeds a parameter to the second dropdown to update it's
list. If the second dropdown has a SelectedValue set, then it returns
the error. If it is not set (which leaves way too much room for user
error since it will auto default to the top of the list) it works fine.
I need this to work, and it seems with as easy as everything else is
with the gridview that this is something relatively silly to get stuck
on. Thanks in advance for everyone's help. The code is below...
----------------------------------------CODE------------------------------------------------------
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="GridViewDataSource"
AllowPaging="True" AllowSorting="True" CellPadding="4"
ForeColor="#333333" GridLines="None" PageSize="15"
DataKeyNames="CD_PID">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField Visible="False"
ShowDeleteButton="True" DeleteText="Delete Vehicle" />
<asp:TemplateField HeaderText="Year"
SortExpression="CD_ModelYear">
<EditItemTemplate>
<aspropDownList ID="DropDownList1"
runat="server" SelectedValue='<%# Bind("CD_ModelYear") %>'>
<asp:ListItem>1969</asp:ListItem>
<asp:ListItem>1970</asp:ListItem>
<asp:ListItem>1971</asp:ListItem>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("CD_ModelYear") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Make"
SortExpression="MAN_Description">
<EditItemTemplate>
<aspropDownList ID="DDMakeEdit"
runat="server" AutoPostBack="True" DataSourceID="ManuDataSource"
DataTextField="MAN_Description"
DataValueField="MAN_ID" SelectedValue='<%# Eval("CD_ManID") %>'
OnDataBinding="Page_Load" OnDataBound="Page_Load">
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("MAN_Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Model"
SortExpression="MOD_Description">
<EditItemTemplate>
<aspropDownList ID="DDModelEdit"
runat="server" DataSourceID="ModelDataSource"
DataTextField="MOD_Description"
DataValueField="MOD_ID" SelectedValue='<%# "CD_ModID" %>'>
</aspropDownList>
<asp:SqlDataSource ID="ModelDataSource"
runat="server" ConnectionString="<%$
ConnectionStrings:JTMConnectionString %>"
SelectCommand="sp_getmodels"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="DDMakeEdit"
Name="MAN_ID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%#
Bind("MOD_Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Car Type"
SortExpression="TYP_Description">
<EditItemTemplate>
<aspropDownList ID="DropDownList2"
runat="server" DataSourceID="CarTypeDataSource"
DataTextField="TYP_Description"
DataValueField="TYP_ID" SelectedValue='<%# Bind("TYP_ID") %>'>
</aspropDownList><asp:SqlDataSource
ID="CarTypeDataSource" runat="server" ConnectionString="<%$
ConnectionStrings:JTMConnectionString %>"
SelectCommand="sp_gettypes"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("TYP_Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Engine"
SortExpression="ENG_Description">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%#
Bind("ENG_Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Transmission"
SortExpression="CD_TransType">
<EditItemTemplate>
<aspropDownList ID="DDTransEdit"
runat="server" SelectedValue='<%# Bind("CD_TransType") %>'>
<asp:ListItem>Automatic</asp:ListItem>
<asp:ListItem>Manual</asp:ListItem>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%#
Bind("CD_TransType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Sold"
SortExpression="CS_DateSold">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"
Text='<%# Bind("CS_DateSold", "{0:d}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%#
Bind("CS_DateSold", "{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ending Bid"
SortExpression="CS_EndingPrice">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("CS_EndingPrice", "{0:C}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#
Bind("CS_EndingPrice", "{0:c}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CS_TotalBids"
HeaderText="Total # of Bids" SortExpression="CS_TotalBids" />
<asp:BoundField DataField="CD_VIN" HeaderText="Vin #"
SortExpression="CD_VIN" />
<asp:CheckBoxField DataField="CS_ReserveMet"
HeaderText="Reserve Met" SortExpression="CS_ReserveMet" />
<asp:CheckBoxField DataField="CS_Sold"
HeaderText="Sold" SortExpression="CS_Sold" />
<asp:CheckBoxField DataField="CD_Clone" HeaderText="Is
a Clone?" SortExpression="CD_Clone" />
<asp:CheckBoxField DataField="CD_EngineMatch"
HeaderText="Engine Match" SortExpression="CD_EngineMatch" />
<asp:CheckBoxField DataField="CD_TransMatch"
HeaderText="Tran. Match" SortExpression="CD_TransMatch" />
<asp:CheckBoxField DataField="CD_CorrectEngSize"
HeaderText="Correct Eng. Size" SortExpression="CD_CorrectEngSize" />
<asp:CheckBoxField DataField="CD_EngineInc"
HeaderText="Engine Included" SortExpression="CD_EngineInc" />
<asp:CheckBoxField DataField="CD_TransInc"
HeaderText="Transmission Included" SortExpression="CD_TransInc" />
<asp:BoundField DataField="CD_PID" HeaderText="CD_PID"
InsertVisible="False" SortExpression="CD_PID"
Visible="False" />
</Columns>
<FooterStyle BackColor="#5D7B9D" BorderStyle="Solid"
Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" BorderStyle="Solid"
BorderWidth="1px" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775"
/>
</asp:GridView>
</div>
<asp:SqlDataSource ID="GridViewDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:JTMConnectionString %>"
SelectCommand="sp_GetCarDetails"
SelectCommandType="StoredProcedure" DeleteCommand="sp_deletevehicle"
DeleteCommandType="StoredProcedure" >
<DeleteParameters><asparameter name="CD_PID" Type="Int32"
/></DeleteParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="ManuDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:JTMConnectionString %>"
SelectCommand="sp_getmanu"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
----------------------------------------CODE------------------------------------------------------
dropdownlists while in edit mode. Now I can bind the data to the
dropdownlists just fine. My problem is that the second dropdown depends
on the first dropdown to pass a parameter to it. If I have a
selectedvalue set to the second drop down, when i select a new value
from the first drop down it gives me this error.
"Databinding methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."
After searching around for nearly a whole day, I have tried a million
things, including something like what was done here
http://www.webswapp.com/CodeSamples/viewsource.aspx?file=\aspnet20\FormView1.aspx
summary: The first dropdown has autopostback set to true, on
autopostback it feeds a parameter to the second dropdown to update it's
list. If the second dropdown has a SelectedValue set, then it returns
the error. If it is not set (which leaves way too much room for user
error since it will auto default to the top of the list) it works fine.
I need this to work, and it seems with as easy as everything else is
with the gridview that this is something relatively silly to get stuck
on. Thanks in advance for everyone's help. The code is below...
----------------------------------------CODE------------------------------------------------------
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="GridViewDataSource"
AllowPaging="True" AllowSorting="True" CellPadding="4"
ForeColor="#333333" GridLines="None" PageSize="15"
DataKeyNames="CD_PID">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField Visible="False"
ShowDeleteButton="True" DeleteText="Delete Vehicle" />
<asp:TemplateField HeaderText="Year"
SortExpression="CD_ModelYear">
<EditItemTemplate>
<aspropDownList ID="DropDownList1"
runat="server" SelectedValue='<%# Bind("CD_ModelYear") %>'>
<asp:ListItem>1969</asp:ListItem>
<asp:ListItem>1970</asp:ListItem>
<asp:ListItem>1971</asp:ListItem>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("CD_ModelYear") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Make"
SortExpression="MAN_Description">
<EditItemTemplate>
<aspropDownList ID="DDMakeEdit"
runat="server" AutoPostBack="True" DataSourceID="ManuDataSource"
DataTextField="MAN_Description"
DataValueField="MAN_ID" SelectedValue='<%# Eval("CD_ManID") %>'
OnDataBinding="Page_Load" OnDataBound="Page_Load">
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("MAN_Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Model"
SortExpression="MOD_Description">
<EditItemTemplate>
<aspropDownList ID="DDModelEdit"
runat="server" DataSourceID="ModelDataSource"
DataTextField="MOD_Description"
DataValueField="MOD_ID" SelectedValue='<%# "CD_ModID" %>'>
</aspropDownList>
<asp:SqlDataSource ID="ModelDataSource"
runat="server" ConnectionString="<%$
ConnectionStrings:JTMConnectionString %>"
SelectCommand="sp_getmodels"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="DDMakeEdit"
Name="MAN_ID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%#
Bind("MOD_Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Car Type"
SortExpression="TYP_Description">
<EditItemTemplate>
<aspropDownList ID="DropDownList2"
runat="server" DataSourceID="CarTypeDataSource"
DataTextField="TYP_Description"
DataValueField="TYP_ID" SelectedValue='<%# Bind("TYP_ID") %>'>
</aspropDownList><asp:SqlDataSource
ID="CarTypeDataSource" runat="server" ConnectionString="<%$
ConnectionStrings:JTMConnectionString %>"
SelectCommand="sp_gettypes"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("TYP_Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Engine"
SortExpression="ENG_Description">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%#
Bind("ENG_Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Transmission"
SortExpression="CD_TransType">
<EditItemTemplate>
<aspropDownList ID="DDTransEdit"
runat="server" SelectedValue='<%# Bind("CD_TransType") %>'>
<asp:ListItem>Automatic</asp:ListItem>
<asp:ListItem>Manual</asp:ListItem>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%#
Bind("CD_TransType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Sold"
SortExpression="CS_DateSold">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"
Text='<%# Bind("CS_DateSold", "{0:d}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%#
Bind("CS_DateSold", "{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ending Bid"
SortExpression="CS_EndingPrice">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("CS_EndingPrice", "{0:C}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#
Bind("CS_EndingPrice", "{0:c}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CS_TotalBids"
HeaderText="Total # of Bids" SortExpression="CS_TotalBids" />
<asp:BoundField DataField="CD_VIN" HeaderText="Vin #"
SortExpression="CD_VIN" />
<asp:CheckBoxField DataField="CS_ReserveMet"
HeaderText="Reserve Met" SortExpression="CS_ReserveMet" />
<asp:CheckBoxField DataField="CS_Sold"
HeaderText="Sold" SortExpression="CS_Sold" />
<asp:CheckBoxField DataField="CD_Clone" HeaderText="Is
a Clone?" SortExpression="CD_Clone" />
<asp:CheckBoxField DataField="CD_EngineMatch"
HeaderText="Engine Match" SortExpression="CD_EngineMatch" />
<asp:CheckBoxField DataField="CD_TransMatch"
HeaderText="Tran. Match" SortExpression="CD_TransMatch" />
<asp:CheckBoxField DataField="CD_CorrectEngSize"
HeaderText="Correct Eng. Size" SortExpression="CD_CorrectEngSize" />
<asp:CheckBoxField DataField="CD_EngineInc"
HeaderText="Engine Included" SortExpression="CD_EngineInc" />
<asp:CheckBoxField DataField="CD_TransInc"
HeaderText="Transmission Included" SortExpression="CD_TransInc" />
<asp:BoundField DataField="CD_PID" HeaderText="CD_PID"
InsertVisible="False" SortExpression="CD_PID"
Visible="False" />
</Columns>
<FooterStyle BackColor="#5D7B9D" BorderStyle="Solid"
Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" BorderStyle="Solid"
BorderWidth="1px" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775"
/>
</asp:GridView>
</div>
<asp:SqlDataSource ID="GridViewDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:JTMConnectionString %>"
SelectCommand="sp_GetCarDetails"
SelectCommandType="StoredProcedure" DeleteCommand="sp_deletevehicle"
DeleteCommandType="StoredProcedure" >
<DeleteParameters><asparameter name="CD_PID" Type="Int32"
/></DeleteParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="ManuDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:JTMConnectionString %>"
SelectCommand="sp_getmanu"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
----------------------------------------CODE------------------------------------------------------