如何在ASP.NET C#中使用dropdownlist值设置条件 [英] how to set condition with dropdownlist values in asp.net c#

查看:78
本文介绍了如何在ASP.NET C#中使用dropdownlist值设置条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何在asp.net c#中使用dropdownlist设置条件
我正在开发一个应用程序,用户可以从数据库中选择绘画尺寸,主题和服务类型,并且可以正确显示数据,但是客户希望在此页面中添加另一个下拉列表,以通过该新的下拉列表计算印度和印度以外的价格,我的值未显示正确的数据,我想知道应该在搜索按钮点击中将这个新概念(印度和印度以外)添加到何处.请告诉我我的代码是..

Pls some one tell that how to set condition with dropdownlist in asp.net c#
i am developing application in which, user select painting size, subject and type of service from database, and it correctly showing data but client want to add another dropdownlist in this page to calculate the price in india and out of india from this new dropdownlist , my values are not showing proper data and i want to know where should i add this new concept(in india and out of india) in my search button click. pls some one tell my code is..

Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("cn").ConnectionString)
            Dim cmd As New SqlCommand()

            con.Open()
            ad = New SqlClient.SqlDataAdapter("select * from detailss where services like '" & DropDownList3.SelectedValue & "' and size like '" & DropDownList1.SelectedValue & "' and subject like '" & DropDownList4.SelectedValue & "'", con)
            dt = New DataTable("dell")
            ad.Fill(dt)

            If dt.Rows.Count > 0 Then
                Label2.Text = dt.Rows(0)("price").ToString()
                Label3.Text = dt.Rows(0)("doller").ToString()

                If DropDownList2.SelectedValue.ToString() <> "India" Then
                    'Add amount

                    'Label4.Text = Session["Price"].ToString()  / 44;

                    ' Label6.Text = dts.Rows(0)("priceday").ToString() / 10

                    'Label1.Visible = True
                    Label2.Visible = True
                    Label3.Visible = True
                    Label4.Visible = True
                    Label5.Visible = True
                    Label6.Visible = True
                    Label7.Visible = False
                    Label8.Visible = False
                    Label9.Visible = True
                    Label10.Visible = True
                    Label13.Visible = True
                    Label14.Visible = True
                    Button2.Visible = True
                    Label24.Visible = False
                    Label25.Visible = True

                    Label6.Text = dt.Rows(0)("services").ToString()
                    Label10.Text = dt.Rows(0)("price").ToString() / 2
                    Label12.Text = Label10.Text / 46

                    Label4.Text = dt.Rows(0)("price").ToString() / 46
                    Label7.Text = dt.Rows(0)("price").ToString() + 150
                    Label9.Text = dt.Rows(0)("doller").ToString() + 40

                    Label13.Text = dt.Rows(0)("size").ToString()
                    Label14.Text = dt.Rows(0)("subject").ToString()

                    Session("pricedoller1") = Label12.Text
                    'Session("priceday2") = Label4.Text
                    'Label11.Text = (Convert.ToInt32(Session("priceday2")) + 40).ToString()
                    Label4.Visible = True
                    Label5.Visible = False
                Else
                    'Dont add amount
                    'Label11.Text = "No Shipping Charges in India"

                    'Label4.Text = Session["Price"].ToString()  / 44;

                    'Label1.Visible = True
                    Label2.Visible = True
                    Label3.Visible = True
                    Label4.Visible = True
                    Label5.Visible = True
                    Label6.Visible = True
                    Label7.Visible = True
                    Label8.Visible = False
                    Label9.Visible = True
                    Label10.Visible = True
                    Label13.Visible = True
                    Label14.Visible = True
                    Button2.Visible = True

                    Label4.Text = (Convert.ToInt32(Session("priceday1")) / 46).ToString()
                    Label7.Text = dt.Rows(0)("price").ToString() + 150
                    Label7.Visible = True
                    Label4.Visible = True
                    Label5.Visible = False
End If

推荐答案

很难弄清楚您在做什么,因为您已经为所有控件使用了默认名称(不好的主意!),并且您已经得到了不必要重复的代码块.无论出于何种原因,您还会有魔术数字在浮动,我们不知道它们是用来干什么的.

您只进行了少量更改,但是这些更改被埋在大块的噪音"中.

您确实需要回过头来重写此内容,以便您和任何试图帮助您的人都可以知道发生了什么.任何从您那里继承并尝试支持该项目的人都将废弃整个项目并从头开始对其进行重写.

为什么?因为根本没有数据模型!您正在传递将它们存储在没有任何有意义名称的Label控件中的值!您对服务项目的整个视图"完全存储在Label控件中.你不那样做.您填充某种表示数据库返回的服务项的对象,然后将各种ASP.NET控件绑定到该对象的属性.该对象还将根据您的页面控件告诉它的运送目的地来更改其显示的价格和运送成本属性.
It''s very difficult to figure out what you''re doing because you''ve used the default names for all of your controls (bad idea!) and you''ve got blocks of code that are needlessly duplicated. You''ve also got magic number floating around for whatever reason and we have no idea what they''re used for.

You''re only making a small number of changes, but those changes are buried in large blocks of "noise".

You really need to go back and rewrite this so both YOU, and anyone trying to help you, can figure out what''s going on. Anyone who inherits this project from you and tries to support it is just going to scrap the entire thing and rewrite it from scratch.

Why? Because you have no data model at all! You''re passing values around storing them in Label controls which don''t have any meaningful names! You''re entire "view" of a service item is stored entirely in Label controls. You don''t do that. You populate some kind of object that represents a service item returned by your database, then you bind the various ASP.NET controls to the properties of this object. That object will also change its displayed price and shipping cost properties based on the shipping destination your page controls tell it.


这篇关于如何在ASP.NET C#中使用dropdownlist值设置条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆