Ciao a tutti!
ho creato una pagina in asp.net con due gridview in modalità master-detail. Se nella detail provo a modificare un record, dove uno dei campi è stato creato un come una DropdownList, mi viene dato questo errore:
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."
Utilizzando il boundfield non posso inserire la DDL per le modifiche, riesco solo a visualizzare, quindi o utilizzo ItemInsertTemplate o UpdateItemTemplate, ma l'errore è sempre lo stesso.
Ecco il codice:
<asp:LinqDataSource ID="LinqDataSource4" runat="server"
ContextTypeName="CAMDataContext"
TableName="Def_Code_Lists" EnableViewState="true" StoreOriginalValuesInViewState="true" EnableUpdate="true">
<SelectParameters>
<asp:Parameter Name="DEF_CODE" />
</SelectParameters>
</asp:LinqDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
BackColor="#CCCCCC" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
ForeColor="Black" Font-Bold="True" DataKeyNames="CAM_PDO_Details_ID"
DataSourceID="LinqDataSource5" AutoGenerateEditButton="True" EnableViewState="False" >
<RowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbDelete" runat="server" CommandName="Delete"
onclientclick="if (!confirm('Deleting record. Are you sure?')) return false">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CAM_PDO_Details_ID" HeaderText="CAM_PDO_Details_ID"
InsertVisible="False" ReadOnly="True" SortExpression="CAM_PDO_Details_ID" />
<asp:BoundField DataField="FK_CAM_PDO_ID" HeaderText="FK_CAM_PDO_ID"
SortExpression="FK_CAM_PDO_ID" />
<asp:BoundField DataField="ME_ID_MARK_OUT" HeaderText="ME_ID_MARK_OUT"
SortExpression="ME_ID_MARK_OUT" />
<asp:TemplateField HeaderText="DEF_CODE" SortExpression="DEF_CODE" >
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="LinqDataSource4" DataValueField="DEF_CODE" SelectedValue='<%# Bind("DEF_CODE") %>' ItemStyle-Font-Bold="false">
</asp:DropDownList>
</EditItemTemplate>
<%--</asp:TemplateField>--%>
<ItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("DEF_CODE") %>' Visible="true" AutoPostBack="True" BackColor="White" BorderStyle="None" ItemStyle-Font-Bold="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DEF_SURF_CODE" SortExpression="DEF_SURF_CODE" >
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DEF_SURF_CODE") %>' Height="22px" Width="40px" MaxLength="2" Visible="true" ItemStyle-Font-Bold="false"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DEF_SURF_CODE") %>' MaxLength="2" Visible="true" ItemStyle-Font-Bold="false" AutoPostBack="True" BackColor="White" BorderStyle="None"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DEF_SERVITY_VALUE"
SortExpression="DEF_SERVITY_VALUE">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"
Text='<%# Bind("DEF_SERVITY_VALUE") %>' Height="22px" Width="40px" ItemStyle-Font-Bold="false"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox3" ErrorMessage="Enter a numeric value"
Type="Integer" ValueToCompare="TextBox3" Text="Enter a numeric value" Operator="DataTypeCheck"></asp:CompareValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("DEF_SERVITY_VALUE") %>' Font-Bold="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DEF_SRC_CODE" SortExpression="DEF_SRC_CODE">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("DEF_SRC_CODE") %>' ItemStyle-Font-Bold="false" Height="22px" Width="40px" MaxLength="1" Visible="true"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("DEF_SRC_CODE") %>' ItemStyle-Font-Bold="false" MaxLength="1" Visible="true" AutoPostBack="True" BackColor="White" BorderStyle="None"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#ee9b31" ForeColor="Black" Font-Bold="True"/>
<HeaderStyle BackColor="#004D3D" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource5" runat="server"
ContextTypeName="CAMDataContext" TableName="CAM_PDO_Details"
EnableDelete="True" EnableInsert="True"
EnableUpdate="True" Where="FK_CAM_PDO_ID==@FK_CAM_PDO_ID">
<WhereParameters>
<asp:ControlParameter ControlID="GridView1" DefaultValue="0"
Name="FK_CAM_PDO_ID" PropertyName="SelectedValue" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>