把DataList1的AutoPostBack属性设为true
DataList1.DataSource = ds;
this.category.DataTextField = "要显示的列名";
DataList1.DataValueField = "id";
String lsid = Convert.ToInt32( this.DataList1.SelectedValue );
DataList1.DataBind();
DataList1.DataSource = ds;
this.category.DataTextField = "要显示的列名";
DataList1.DataValueField = "id";
String lsid = Convert.ToInt32( this.DataList1.SelectedValue );
DataList1.DataBind();
解决方案 »
- 如何禁止Button接收回车事件?
- 在线网页录音
- qq在线聊天的代码在那里找呢??有官方的地址么
- 请教一下,在VS2005里面如何新建一个用户自定义控件的项目呀?
- 关于访问ACCESS数据库的问题,能够打开,就是不是写入数据!
- 子目录的名称搜索的问题 40分求教
- 用c#做asp.net能不能象javascript一样弹出个对话框??
- 如果使得在编辑datagrid中的某一行时,其中的某个字段变为下拉式菜单,并提供选择?
- 大家帮忙看看我的代码问题在那儿,为什么if,else,catch中的response.redirect都运行呢?
- C# DateTime 转换成ISO 8601 时间格式的 DateTime时间类型,而非string
- 如何实现这样的DATALIST?????
- 关于DATAGRID更新按钮的使用问题,请教大家了
<HTML>
<body style="font: x-small Verdana, Arial, sans-serif;">
<!-- Begin Web Form -->
<form id="CustomerOrderDataGrid" method="post" runat="server">
<p><a href="/DayOfDotNet/">Parent Directory</a></p> <!-- Begin DataGrid -->
<asp:DataGrid id="CustomerDataGrid" runat="server"
AutoGenerateColumns="False"
CellPadding="2" CellSpacing="0"
Font-Names="Verdana, Arial, sans-serif"
BorderColor="Black" BorderWidth="1"
GridLines="Horizontal"
OnItemDataBound="CustomerDataGrid_OnItemDataBound"> <HeaderStyle
Font-Bold="True" Font-Size="small"
Font-Name="Arial"
BackColor="Maroon" ForeColor="White" /> <ItemStyle Font-Size="x-small" /> <AlternatingItemStyle BackColor="Tan" /> <Columns> <asp:HyperLinkColumn
DataTextField="CustomerID"
DataNavigateUrlField="CustomerID"
DataNavigateUrlFormatString="OrderDetailDataGrid.aspx?customerid={0}"
HeaderText="ID"
ItemStyle-VerticalAlign="Top" /> <asp:TemplateColumn ItemStyle-VerticalAlign="Top" HeaderText="Customer">
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "CompanyName") %></b><br>
<%# DataBinder.Eval(Container.DataItem, "Address" ) %><br>
<%# DataBinder.Eval(Container.DataItem, "City" ) %>,
<%# DataBinder.Eval(Container.DataItem, "Region") %>
<%# DataBinder.Eval(Container.DataItem, "PostalCode" ) %><br>
<br>
<%# DataBinder.Eval(Container.DataItem, "ContactName" ) %><br>
<%# DataBinder.Eval(Container.DataItem, "ContactTitle" ) %><br>
<%# DataBinder.Eval(Container.DataItem, "Phone" ) %>
</ItemTemplate>
</asp:TemplateColumn> <asp:TemplateColumn
ItemStyle-VerticalAlign="Top"
HeaderText="Orders"
ItemStyle-Width="100%"> <ItemTemplate> <asp:DataGrid runat="server"
AutogenerateColumns="False"
Width="100%"
GridLines="Horizontal"
BorderColor="Black"
BorderWidth="1"
Font-Name="Verdana"
Font-Size="x-small"
DataSource='<%# getOrdersDataSource( (string)DataBinder.Eval(Container.DataItem, "CustomerID") ) %>'> <HeaderStyle
BackColor="Black"
ForeColor="White"
Font-Bold="True" /> <ItemStyle BackColor="White" /> <AlternatingItemStyle BackColor="Silver" /> <Columns>
<asp:BoundColumn DataField="OrderID" HeaderText="Order ID" />
<asp:TemplateColumn>
<ItemTemplate>
<b>Order Date: </b>
<%# DataBinder.Eval(Container.DataItem, "OrderDate", "{0:D}" ) %>
<br>
<b>Shipped Date: </b>
<%# DataBinder.Eval(Container.DataItem, "OrderDate", "{0:D}" ) %>
<br>
<b>Required Date: </b>
<%# DataBinder.Eval(Container.DataItem, "OrderDate", "{0:D}" ) %>
<br>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<!-- End DataGrid -->
</form>
<!-- End Web Form -->
</body>
</HTML>------------------------------------------------------------------using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; namespace MasterDetail
{
public class CustomerOrderDataGrid : System.Web.UI.Page
{
protected DataGrid CustomerDataGrid;
private DataSet ds = new DataSet();
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindData();
}
} private void BindData()
{
string sqlStmt = "SELECT * FROM Customers; SELECT * FROM Orders";
string conString = "server=localhost;database=Northwind;uid=sa;pwd=;";
SqlDataAdapter sda = new SqlDataAdapter(sqlStmt, conString);
sda.Fill(ds);
ds.Tables[0].TableName = "Customers";
ds.Tables[1].TableName = "Orders";
CustomerDataGrid.DataSource = ds.Tables["Customers"];
CustomerDataGrid.DataBind();
} protected DataView getOrdersDataSource(string _customerID)
{
DataView _orders = ds.Tables["Orders"].DefaultView;
_orders.RowFilter = "CustomerID='" + _customerID + "'";
return _orders;
}
}
}
在里边在动态ADD一个datalist
演示
http://aspxboy.com/forum