<InsertItemTemplate>
<asp:DropDownList ID="TxtsiteInsert" runat="server" Text='<%# Bind("SITE")
%>' TabIndex="5" AutoPostBack="True" DataSourceID="inventsite"
DataTextField="SITEID" DataValueField="SITEID"
OnSelectedIndexChanged="sitedropdown_SelectedIndexChanged">
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="TxtSite" runat="server" Text='<%# Bind("SITE") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Warehouse" SortExpression="WAREHOUSE">
<EditItemTemplate>
<asp:TextBox ID="TxtWarehouseEdit" runat="server" Text='<%# Bind("WAREHOUSE")
%>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="TxtWarehouseInsert" runat="server"
TabIndex="6" AutoPostBack="True"
SelectedValue='<%# Bind("WAREHOUSE") %>'>
</asp:DropDownList>
这是我的vb编码:
Protected Sub sitedropdown_SelectedIndexChanged(ByVal sender As Object,
ByVal e As EventArgs)
Dim IdTxtsiteInsert As DropDownList =
CType(DetailsView3.Rows(0).FindControl("TxtsiteInsert"), DropDownList)
Fillwarehouse(IdTxtsiteInsert.Text)
End Sub
Public Sub Fillwarehouse(ByVal siteid As String)
Dim ddr As DropDownList =
DirectCast(DetailsView3.Rows(0).FindControl("TxtWarehouseInsert"),
DropDownList)
Dim strConn As String =WebConfigurationManager.ConnectionStrings("BMGINC_DYNAX09_ProdConnectionString").
ConnectionString
Dim con As New SqlConnection(strConn)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select InventLocationId, Name from InventLocation
where InventSiteId ='" & siteid & "'"
cmd.Parameters.AddWithValue("InventSiteId", siteid)
Dim objDs As New DataSet()
Dim dAdapter As New SqlDataAdapter()
dAdapter.SelectCommand = cmd
con.Open()
dAdapter.Fill(objDs)
con.Close()
If objDs.Tables(0).Rows.Count > 0 Then
ddr.DataSource = objDs.Tables(0)
ddr.DataTextField = "InventLocationId"
ddr.DataValueField = "InventLocationId"
ddr.DataBind()
ddr.Items.Insert(0, "-Select-")
Else
LblError.Text = "No Warehouse found"
End If
End Sub
运行代码时,我得到的数据绑定方法(例如Eval(),XPath()和Bind())只能在发生数据绑定控制错误的情况下使用,并且所选值未存储在表中。 我需要将场地和仓库存储到我的表中,但不允许我存储仓库记录,如何将这个选定的仓库下拉值传递到我的斧头表中