简体   繁体   English

未获取下拉列表的选定值

[英]Not getting the selected value of dropdownlist

I have a field named country in Invoice.aspx form.我在 Invoice.aspx 表单中有一个名为 country 的字段。 I have the below code.我有以下代码。

invoice.aspx发票.aspx

<asp:DropDownList ID="lstCountryy" runat="server" Width="216px" Height="27px" AutoPostback="false">
</asp:DropDownList>

invoice.aspx.cs发票.aspx.cs

lstCountryy.SelectedValue = dtInquiry.Rows[0]["country"].ToString();

Page load:页面加载:

 protected void Page_Load(object sender, EventArgs e)
    {
        txtTotal.Attributes.Add("readonly", "readonly");
        txtvatt.Attributes.Add("readonly", "readonly");//added by chetan
        txtDiscount.Attributes.Add("readonly", "readonly");//added by chetan
        txtAmountInWords.Attributes.Add("readonly", "readonly");
        if (!IsPostBack)
        {           
            loadInvoiceDetails();

            //SetAllCountries();//added by chetan

            if (lstCountryy.SelectedValue == "U.A.E" || lstCountryy.SelectedValue == "BAHRAIN" || lstCountryy.SelectedValue == "SAUDI ARABIA")
            {


                txtvat.Text = "";
                txtvatt.Text = "";
                txtBankCharge.Text = "";
                txtDiscount.Text = "";
                txtDiscountText.Text = "";
                txtTotal.Text = "";

                vattr.Style.Add("display", "float");
                trdeclaration.Visible = false;

                //txtvat.Enabled = true;

            }
            else
            {
                txtvat.Text = "";
                txtvatt.Text = "";
                txtBankCharge.Text = "";
                txtDiscount.Text = "";
                txtDiscountText.Text = "";
                txtTotal.Text = "";


                vattr.Style.Add("display", "none");



                trdeclaration.Visible = true;
            }

        }
      
       
    }

Bind dropdownlist:绑定下拉列表:

protected void SetAllCountries()
    {
        try
        {
            string queryStrUserType = "SELECT country_id,country_name FROM  crm_countries";
            ClassDtBaseConnect clsDtResult = new ClassDtBaseConnect();
            DataTable dt = clsDtResult.GetDataTable(queryStrUserType);
            lstCountryy.DataSource = dt;
            lstCountryy.DataValueField = "country_id";
            lstCountryy.DataTextField = "country_name";
            lstCountryy.DataBind();
            lstCountryy.Items.Insert(0, "--Select--");

        }
        catch (Exception Ex)
        {

        }
    }

dtInquiry is my Inquiry table in which country field is there and I am fetching the value from inquiry form to invoice form. dtInquiry 是我的查询表,其中有国家/地区字段,我正在从查询表中获取值到发票表。 I am not getting the selected value;我没有得到选定的值; it shows blank ("").它显示空白(“”)。 I don't know what's wrong with that.我不知道这有什么问题。 I am a beginner in C#.我是 C# 的初学者。

I was not getting the selected value.It should be like this: SetAllCountries Should be first and then loadinvoicedetails.我没有得到选定的值。它应该是这样的:SetAllCountries 应该是第一个然后加载invoicedetails。

protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {    
            SetAllCountries();     
            loadInvoiceDetails();
            .....
            .....
        }
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM