本文介绍了为什么当我选择其他时drop downlist4的值没有改变.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么当我选择其他选项时drop downlist4的值没有变化.它仅从满足第一个条件的表中获取第一条记录.下拉列表与dropdownlist 3链接.

我的HTML部分和CS部分在下面给出.


HTML部分

Why the value of drop downlist4 is not changing when i select other.It is getting only first record from table which satisfied first condition.The drop down list is linked with dropdownlist 3.

My HTML part and CS part is given below .


HTML part

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Selection4go.aspx.cs" Inherits="selection4go" %>

<!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">
</head>
<body>
    <form id="form1"  runat="server">
    <div align="center">
    
        <table class="style1">
            <tr>
                <td>
                     </td>
            </tr>
            <tr>
                <td>
                    <table class="style2">
                        <tr>
                            <td>
                                 </td>
                            <td>
                                 </td>
                            <td>
                                <asp:PlaceHolder ID="ph1" runat="server"></asp:PlaceHolder>
                            </td>
                            <td>
                                 </td>
                        </tr>
                        <tr>
                            <td>
                                 </td>
                            <td>
                                Class</td>
                            <td>
                                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 

                                    DataSourceID="SqlDataSource1" DataTextField="class_name" 

                                    DataValueField="class_name">
                                </asp:DropDownList>
                                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

                                    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 

                                    SelectCommand="SELECT * FROM [class]"></asp:SqlDataSource>
                            </td>
                            <td>
                                 </td>
                        </tr>
                        <tr>
                            <td>
                                 </td>
                            <td>
                                Board</td>
                            <td>
                                <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" 

                                    DataSourceID="SqlDataSource2" DataTextField="board" DataValueField="board">
                                </asp:DropDownList>
                                <asp:SqlDataSource ID="SqlDataSource2" runat="server" 

                                    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 

                                    SelectCommand="SELECT * FROM [board]"></asp:SqlDataSource>
                            </td>
                            <td>
                                 </td>
                        </tr>
                        <tr>
                            <td>
                                 </td>
                            <td>
                                City</td>
                            <td>
                                <asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True" 

                                    DataSourceID="SqlDataSource3" DataTextField="cityname" 

                                    DataValueField="stateid">
                                </asp:DropDownList>
                                <asp:SqlDataSource ID="SqlDataSource3" runat="server" 

                                    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 

                                    SelectCommand="SELECT * FROM [city]"></asp:SqlDataSource>
                            </td>
                            <td>
                                 </td>
                        </tr>
                        <tr>
                            <td>
                                 </td>
                            <td>
                                State</td>
                            <td>
                                <asp:DropDownList ID="DropDownList4" runat="server" 

                                    DataSourceID="SqlDataSource4" DataTextField="statename" 

                                    DataValueField="stateid" AutoPostBack="True">
                                </asp:DropDownList>
                                <asp:SqlDataSource ID="SqlDataSource4" runat="server" 

                                    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 

                                    SelectCommand="SELECT * FROM [state] WHERE ([stateid] = @stateid)">
                                    <SelectParameters>
                                        <asp:ControlParameter ControlID="DropDownList3" DefaultValue="-99" 

                                            Name="stateid" PropertyName="SelectedValue" Type="String" />
                                    </SelectParameters>
                                </asp:SqlDataSource>
                            </td>
                            <td>
                                 </td>
                        </tr>
                        <tr>
                            <td>
                                 </td>
                            <td>
                                 </td>
                            <td>
                                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 

                                    Text="PROCEED==>" Width="215px" />
                            </td>
                            <td>
                                 </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                     </td>
            </tr>
        </table>
    
    </div>
    </form>
</body>
</html>


CS零件


CS Part

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

public partial class selection4go : System.Web.UI.Page
    {
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        
        if (Request.QueryString["t1"].ToString() != null)
        {
          string  mail = Request.QueryString["t1"].ToString();
            SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
            con.Open();
            ds = new DataSet();
            string sql = "select email,rclass,board,city,state from registration where email='" + mail +"'";
            da = new SqlDataAdapter(sql, con);
            da.Fill(ds, "registration");
            DataRow dRow = ds.Tables["registration"].Rows[0];
            string em = dRow.ItemArray.GetValue(0).ToString();
            string s = dRow.ItemArray.GetValue(1).ToString();
            string t = dRow.ItemArray.GetValue(2).ToString();
            string u = dRow.ItemArray.GetValue(3).ToString();
            string v = dRow.ItemArray.GetValue(4).ToString();
            
            int r = 0;
            DataRow[] rs;
            rs = ds.Tables["registration"].Select("email='" + mail + "'");
            r = rs.Length;
            if (r > 0)
            {
                DataRow dr;
                dr = rs[0];
                string m = dr["rclass"].ToString();
                string n = dr["board"].ToString();
                string o = dr["city"].ToString();
                string p = dr["state"].ToString();
                string a, b, c, d;
                a = DropDownList1.SelectedItem.Text.Trim();
                b = DropDownList2.SelectedItem.Text.Trim();
                c = DropDownList3.SelectedItem.Text.Trim();
                d = DropDownList4.SelectedItem.Text.Trim();
                   
                if (m != a)
                {
                    System.Web.UI.WebControls.Label lbl1 = new System.Web.UI.WebControls.Label();
                    lbl1.ForeColor = System.Drawing.Color.Yellow;
                    lbl1.BackColor = System.Drawing.Color.Blue;
                    lbl1.Text = "This ID is not Valid for Class " + a ;
                    ph1.Controls.Add(lbl1);
                }
                else if (n != b)
                {
                    System.Web.UI.WebControls.Label lbl1 = new System.Web.UI.WebControls.Label();
                    lbl1.ForeColor = System.Drawing.Color.Yellow;
                    lbl1.BackColor = System.Drawing.Color.Blue;
                    lbl1.Text = "This ID is not Valid for Board " + b;
                    ph1.Controls.Add(lbl1);
                }
                else if (o != c)
                {
                    System.Web.UI.WebControls.Label lbl1 = new System.Web.UI.WebControls.Label();
                    lbl1.ForeColor = System.Drawing.Color.Yellow;
                    lbl1.BackColor = System.Drawing.Color.Blue;
                    lbl1.Text = "This ID is not Valid for City " + c;
                    ph1.Controls.Add(lbl1);
                }
                else if (p != d)
                {
                    System.Web.UI.WebControls.Label lbl1 = new System.Web.UI.WebControls.Label();
                    lbl1.ForeColor = System.Drawing.Color.Yellow;
                    lbl1.BackColor = System.Drawing.Color.Blue;
                    lbl1.Text = "This ID is not Valid for Board " + d;
                    ph1.Controls.Add(lbl1);
                }
                else
                {
                    Response.Redirect("ANScontrol.aspx");
                }
                
                    
            }
            else
            {
                System.Web.UI.WebControls.Label lbl1 = new System.Web.UI.WebControls.Label();
                lbl1.ForeColor = System.Drawing.Color.Yellow;
                lbl1.BackColor = System.Drawing.Color.Blue;
                lbl1.Text = "Pleasse select Valid Selection as per ur registration";
                ph1.Controls.Add(lbl1);
            }
            
        }
        
        
    }
}

推荐答案




这篇关于为什么当我选择其他时drop downlist4的值没有改变.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:28