如果我们从下拉列表中选择一个值,例如 1 或 2 等,它应该显示特定产品的数量和尺寸。如果我们从下拉列表中选择 2,则数字和大小应显示两次。
问问题
232 次
1 回答
0
查看此示例 ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="No. of Products:"></asp:Label>
<asp:DropDownList ID="ddlItems" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlItems_SelectedIndexChanged">
<asp:ListItem Value="0">-Select-</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
背后的代码
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ddlItems_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlItems.SelectedIndex > 0)
{
DataTable dt = new DataTable();
int cntr=Convert.ToInt32(ddlItems.SelectedValue);
dt.Columns.Add(new DataColumn("SNO",typeof(int)));
dt.Columns.Add(new DataColumn("ProductName",typeof(string)));
dt.Columns["SNO"].AutoIncrement=true;
dt.Columns["SNO"].AutoIncrementSeed = 1;
for(int i=1;i<=cntr;i++)
{
DataRow dr=dt.NewRow();
dr["ProductName"]= " Sample Product Name for Item #"+ i;
dt.Rows.Add(dr);
}
GridView1.DataSource=dt;
GridView1.DataBind();
}
}
}
于 2012-05-14T11:11:31.363 回答