0

私の2番目のドロップダウンリストは選択された会計年度に関連付けられた年があり、2011-2012のような年を選択しようとすると、ボタンクリックでその値が表示されず、代わりに私の選択が2010-2011の最初のものに変更されます最初のドロップダウンから他のプロジェクト コードを選択すると、2 番目の項目ではなく 2 番目のドロップダウン リストの 1 番目の値を選択できますか?.....[何が起こっているのかというと、私の 2 番目のドロップダウンは、私の最初のドロップダウン リストにリンクされた値を表示しています。その 2 番目の値を送信し、2 番目の値を選択すると自動的に 1 番目の値に変更され、結果が表示される場合は送信しますか?]

  using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Data;
    using System.Configuration;


    public partial class Default2 : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
        DataSet ds = new DataSet();
        SqlCommand cmd = new SqlCommand();
        DataTable dt = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {


            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            if (Page.IsPostBack == false)
            {
                string query = "select * from project";
                SqlCommand cmd = new SqlCommand(query, con);
                cmd.CommandType = CommandType.Text;
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adp.Fill(ds);
                DropDownList1.DataSource = ds;
                DropDownList1.DataValueField = ds.Tables[0].Columns[0].ToString();
                DropDownList1.DataTextField = ds.Tables[0].Columns[1].ToString();
                DropDownList1.DataBind();
                DropDownList1.Items.Insert(0, "--Select--");

                cmd.Dispose();
            }

            con.Close();

        }




        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }

            try
            {
                string query1 = "Select * from yearly where pid = " + DropDownList1.SelectedItem.Value.ToString();
                SqlCommand cmd = new SqlCommand(query1, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                adp.Fill(ds);
                DropDownList2.DataSource = ds;

                DropDownList2.DataValueField = ds.Tables[0].Columns[0].ToString();
                DropDownList2.DataTextField = ds.Tables[0].Columns[1].ToString();

                DropDownList2.DataBind();
                DropDownList2.Items.Insert(0, "--Select--");

                cmd.Dispose();
            }
            catch (Exception)
            {

            }

            con.Close();
        }



        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {


            SqlDataAdapter da = new SqlDataAdapter("select pcode,fyyear,date,salary,ta,contigency,nrc,institcharges,others from monthly where pcode=('" + DropDownList1.SelectedItem.ToString() + "' ) AND fyyear=('" + DropDownList2.SelectedItem.ToString() + "')",con);
                DataTable dt = new DataTable();
                da.Fill(dt);
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }

            catch (Exception ex)
            {
                ex.Message.ToString();
            }



        }



    }

i am also attaching aspx code:

    <%@ Page Title="" Language="C#" MasterPageFile="~/grid.master" AutoEventWireup="true" CodeFile="yearwiseex.aspx.cs" Inherits="Default2" %>

    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:Label ID="Label1" runat="server" Text="Select Project Code"></asp:Label>
    &nbsp;
    &nbsp;
    <asp:DropDownList ID="DropDownList1" runat="server"
           Height="20px" Width="130px"
           onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
            AutoPostBack="True"> </asp:DropDownList>

        <asp:Label ID="Label2" runat="server" Text="Select Financial Year"></asp:Label>
        &nbsp;&nbsp;
    &nbsp;&nbsp;
    <asp:DropDownList ID="DropDownList2" runat="server" 
            Height="20px" Width="130px"></asp:DropDownList>


        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
        <br />
        <br />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" style="margin-left: 82px" 
            Width="90%" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" 
            BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical">
            <AlternatingRowStyle BackColor="White" />
            <FooterStyle BackColor="#CCCC99" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#F7F7DE" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FBFBF2" />
            <SortedAscendingHeaderStyle BackColor="#848384" />
            <SortedDescendingCellStyle BackColor="#EAEAD3" />
            <SortedDescendingHeaderStyle BackColor="#575357" />
        </asp:GridView>
        <br />
    &nbsp;<br />
        </asp:Content>
4

1 に答える 1

0

MultiSelect を探していると思います。その場合は、リストボックスを使用します。

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listbox.aspx

...選択モードを「複数」に設定します。

于 2012-11-10T08:18:27.417 に答える