public void Category() { var result = from r in lqDB.Category select new { r.Category1, r.CategoryID }; CID.DataSource = result; CID.DataBind(); } public void Varietes() { int id = Int32.Parse(CID.SelectedValue); var result = from r in lqDB.Varieties select new { r.Varieties1, r.VarietiesID, r.VCID }; VS.DataSource = result; VS.DataBind(); }
这是后台代码
<asp:DropDownList ID="CID" runat="server" DataTextField="Category1" DataValueField="CategoryID" AutoPostBack="True" > <asp:ListItem>VCID</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="VS" runat="server" DataTextField="Varieties1" DataValueField="VarietiesID" AutoPostBack="True"> </asp:DropDownList>
这是前台 我准备实现的是下拉框级联 数据库
CREATE TABLE [dbo].[Category] ( [CategoryID] INT IDENTITY (1, 1) NOT NULL, [Category] NVARCHAR (50) NULL, CONSTRAINT [PK_Category] PRIMARY KEY CLUSTERED ([CategoryID] ASC) ); CREATE TABLE [dbo].[Varieties] ( [VarietiesID] INT IDENTITY (1, 1) NOT NULL, [Varieties] NVARCHAR (50) NULL, [VCID] INT NULL, CONSTRAINT [PK_Varieties] PRIMARY KEY CLUSTERED ([VarietiesID] ASC), CONSTRAINT [FK_Varieties_Category] FOREIGN KEY ([VCID]) REFERENCES [dbo].[Category] ([CategoryID]) ); CREATE TABLE [dbo].[KC] ( [ID] INT IDENTITY (1, 1) NOT NULL, [CategoryID] INT NULL, [VarietiesID] INT NULL, [Type] NVARCHAR (50) NULL, [ColorID] INT NULL, [LayerID] INT NULL, [ThicknessID] INT NULL, [Specification] NVARCHAR (50) NULL, [Meter] NVARCHAR (50) NULL, [Square] NVARCHAR (50) NULL, [Data] NVARCHAR (50) NULL, [Number] INT NULL, [Remark] NVARCHAR (50) NULL, [Nmb] NCHAR (10) NULL, CONSTRAINT [PK_KC] PRIMARY KEY CLUSTERED ([ID] ASC), CONSTRAINT [FK_KC_Layer] FOREIGN KEY ([LayerID]) REFERENCES [dbo].[Layer] ([LayerID]), CONSTRAINT [FK_KC_Category] FOREIGN KEY ([CategoryID]) REFERENCES [dbo].[Category] ([CategoryID]), CONSTRAINT [FK_KC_Varieties] FOREIGN KEY ([VarietiesID]) REFERENCES [dbo].[Varieties] ([VarietiesID]), CONSTRAINT [FK_KC_Color] FOREIGN KEY ([ColorID]) REFERENCES [dbo].[Color] ([ColorID]), CONSTRAINT [FK_KC_Thickness] FOREIGN KEY ([ThicknessID]) REFERENCES [dbo].[Thickness] ([ThicknessID]) );
下拉框级联怎么刷新不了? 我集合写了啊. 求代码
选择的时候下拉框不能实现级联啊.我那里有问题, 麻烦各位帮在下修改一下代码 <span style="color: #FF0000;">where r.ID = id</span> 把那些绑定全部放到非回传判断里 否则 你的dropdownlist启用了自动回传 那你的数据源都会重新加载!!
|