我有一个 DropDownList 从 sql server 中的表中提取值。我希望下拉列表根据用户的选择填充值列表,但也显示我的表格其余部分的内容,以防他们需要更改某些内容。例如:
ddl1 的值为:1, 2, 3, 4, 5 用户选择 5,所以 ddl2 中显示的值为 5,但如果您展开 ddl2 您还会看到值 1、2、3、4...
这是我的加载事件中的代码......
If Not IsPostBack Then
result = dal.dbConnect(DAL.dbType.SqlServer, ConfigurationManager.AppSetting("SQLServerConnection"))
If result = "Successful" Then
Try
dt = dal.ExecuteSelectStoredProc(DAL.dbType.SqlServer, "StoredProc1", "@obj1", DropDownList1.Text)
DropDownList2.DataSource = dt
DropDownList2.DataTextField = dt.Columns.Item(1).ToString
DropDownList2.DataBind()
Catch ex As Exception
End Try
End If
End If
存储过程...
USE [DB1]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[StoredProc1]
@obj1 nvarchar(4)
AS
BEGIN
SET NOCOUNT ON;
SELECT [Obj1], [obj2]
FROM [DB1].[dbo].[Code]
WHERE [obj1] = @obj1
END