看我的:先定义用户控件 usercontrol.ascx(使用xml和使用数据库一样道理)
<%@ import namespace="system.data"%>
<script language="vb" runat=server>
Dim xmlds As DataSet=new dataset()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
xmlds.ReadXml(Server.MapPath("new_class.xml"))
drop.DataSource=xmlds
drop.DataBind()
End Sub
How do I add a DropDownList to EditItemTemplate, using an Access database, and then some?
By: Donny Mack
Level: Beginner
Posted Date: 7/24/2001
Tested with ASP.NET Beta 2 (v.1.0.2914.16)
Click for Printable Version
Click here to download sample code
Member Rating: 3.50 (Rated by 2 members)
Rate This Item
--------------------------------------------------------------------------------
In a recent artlicle we discussed how to populate a DropDownList box from within a DataGrid's Column while the DataGrid was in "edit mode". Well, this article builds off that example, and adds some new elements and features. First, instead of using the SQL we are going to use Access - specifically, the Northwind database. Second, when filling the DropDownList we aren't going to make a seperate call to the database to get the data - instead we are going to use a DataView and filter out the specific rows we need to populate each individual DropDownList. Third, we are going to save the changes back to Access once they have been edited.
Listing 1.1 contains the code we are going to be working with for this example:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
OleDbDa = new OleDbDataAdapter("SELECT S.*, (SELECT COUNT(*) FROM Products AS P WHERE P.SupplierID = S.SupplierID) AS [ProductCount] FROM Suppliers AS S", SqlCon);
ds = new DataSet();
OleDbDa.Fill(ds, "Suppliers");
OleDbDa.SelectCommand = new OleDbCommand("SELECT ProductName, ProductID, SupplierID FROM Products", SqlCon);
OleDbDa.Fill(ds, "Products");
dvProducts = ds.Tables["Products"].DefaultView;
MyDataGrid.DataSource = ds.Tables["Suppliers"];
Page.DataBind();