玉家伙,所以我这样说的: How to set SelectedValue of DropDownList in GridView EditTemplate绑定的DropDownList的SelectedValue到DataValueField为GridView控件更新
和我有同样的问题。但是,我不想将选定的值绑定到显示的文本,而是将值绑定。它们是从SQLDataSource中选择的不同属性。这里是我的DDL代码与它的SqlDataSource:
<asp:DropDownList ID="FoodCodeDropDownList" runat="server"
DataSourceID="Plant_Carton_Food_List"
DataTextField="Food_Description"
DataValueField="PlantMaterial_FoodID"
SelectedValue='<%# Bind("PlantMaterial_FoodID") %>' >
</asp:DropDownList>
<asp:SqlDataSource ID="Plant_Carton_Food_List" runat="server"
ConnectionString="<%$ ConnectionStrings:OMSConnectionString %>"
SelectCommand="SELECT P.PlantMaterial_FoodID,
M.Material_SAP_Value + ' - ' + MD.SAP_Long_Description AS Food_Description
FROM Plant_Carton_Food AS P
LEFT OUTER JOIN Material_Descriptions AS MD
ON P.PlantMaterial_FoodID = MD.Material_ID
LEFT OUTER JOIN Materials AS M
ON P.PlantMaterial_FoodID = M.Material_ID">
</asp:SqlDataSource>
这里是GridView控件的(有删节)的SqlDataSource:
<asp:SqlDataSource ID="Plant_Carton_Table" runat="server"
OldValuesParameterFormatString="old_{0}"
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
OnInserting="Plant_Carton_Food_Table_Inserting"
OnInserted="Plant_Carton_Food_Table_Inserted"
InsertCommand="spPlantCartonInsert" InsertCommandType="StoredProcedure"
SelectCommand="spPlantCartonSelect" SelectCommandType="StoredProcedure"
UpdateCommand="spPlantCartonUpdate" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="Active_Case" Type="Boolean" />
<asp:Parameter Name="PlantMaterial_FoodID" Type="String" />
<asp:Parameter Name="PlantMaterial_CaseID" Type="String" />
...
</UpdateParameters>
...
</asp:SqlDataSource>
最后,我的例外:
数据绑定:' System.Data.DataRowView' 不包含名称为'PlantMaterial_FoodID'的 属性。
我真的没有太多的关于如何通过GridView编辑模板进行数据绑定的知识,但我能够看到正确的值通过OnRowCommand事件处理程序进行更新。如何将这些值传播到SQLDataSource而不会获得NULL?
现在,我想任何关于如何使用GridView模板进行数据绑定的解释都是有益的。谢谢!
也粘贴您的数据源。 – naveen 2011-06-10 03:15:31
@naveen - 为下拉菜单和GridView添加了DataSource。 – BradV 2011-06-10 04:26:19
和datasource/table绑定gridview? PlantMaterial_FoodID不会出现在那里。请贴太 – naveen 2011-06-10 04:33:39