1
嗯,我有帶有DropDownList的'TemplateField'等可編輯字段的GridView。 我的代碼:GridView:在GridView中編輯底層數據
<Columns>
...
<asp:TemplateField SortExpression="Room" HeaderText="Room">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" Runat="server" DataSourceID="categoryDataSource" DataTextField="RoomNumber" DataValueField="RoomNumber" SelectedValue='<%# Bind("Room") %>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("Room") %>' ID="Label1"></asp:Label>
</ItemTemplate>
</Columns>
我DB具有表房間,裏面有行:RoomId,RoomNumber。 在我的DropDownList中,我嘗試設置表格房間的所有值。 表有3行(RoomId,RoomNumber):1 - 20; 2 - 12; 3 - 24
但寫遵循錯誤:
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
參數名:價值 也許有人知道我在哪裏犯了錯誤?
編輯:這裏是SqlDataSource的代碼
<asp:SqlDataSource ID="categoryDataSource" Runat="server"
SelectCommand="SELECT [RoomId], [RoomNumber] FROM [Rooms] ORDER BY [RoomNumber]"
ConnectionString="Data Source=.\MSSQLSERVERR2;AttachDbFilename=|DataDirectory|\ARMDB.MDF;Integrated Security=True;User Instance=True">
</asp:SqlDataSource>
代碼是在這裏(谷歌文檔):https://docs.google.com/document/d/1R7FU5Ka85G2PAbJJ5vj3MM1Tcd4rDNI-ETOw8oSrnxw/edit – Leo 2012-01-12 22:58:20
它不工作...我不明白哪裏有問題... – Leo 2012-01-12 22:59:45