English 中文(简体)
标出后在 as中标出的参数
原标题:displaying of parameter after selection in dropdownlist in asp.net
  • 时间:2012-05-14 10:00:38
  •  标签:
  • asp.net

如果我们从 drop夫名单中选择价值,例如1或2等。 它应当显示特定产品的数量和规模。 如果我们从倒数名单上挑选出2个,那么人数和规模应当有两次显示。

问题回答

Check out this sample 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>
&nbsp;<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>
&nbsp;<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();
        }
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签