下拉列表选择的值不是选中的 [英] Drop down list Selected value is not seleted

查看:155
本文介绍了下拉列表选择的值不是选中的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



下拉列表选择的值是选择总是选择第一个值

我的代码





problem

Drop down list Selected value is select always select the first value
My CODE


public void ddlbind()
       {
           BALBillDetails B = new BALBillDetails();
           DataSet ds = new DataSet();
           B.GetItemNames();
           ddlitems.DataSource = B.GetItemNames();
           ddlitems.DataTextField = "Item_Name";
           ddlitems.DataValueField = "Item_Code";
           ddlitems.DataBind();

       }

protected void ddlitems_SelectedIndexChanged(object sender, EventArgs e)
        {

            BALBillDetails objPrice = new BALBillDetails();
            DataTable dt = new DataTable();
            objPrice.Item_Code = ddlitems.SelectedValue.ToString();
            dt = objPrice.GetItemPrice();
           
            txtPrice.Text = dt.Rows[0]["Sale_Price"].ToString();
     
        }

推荐答案

试试这段代码,我想当你选择下拉列表时你的页面是重定向,当页面重定向时,再次填充下拉列表中的值。

我希望这会对你有所帮助。



Try this code, I think when you are select drop down list your page is redirect, when page is redirect again fill the values in drop down list.
I hope this will be help you.

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlbind();
        }

    }
    public void ddlbind()
    {
        BALBillDetails B = new BALBillDetails();
        DataSet ds = B.GetItemNames();
        ddlitems.DataSource = ds.Tables[0];
        ddlitems.DataTextField = "Item_Name";
        ddlitems.DataValueField = "Item_Code";
        ddlitems.DataBind();

    }


Hi
您的错误在ddlitems.DataSource = B.GetItemNames();

检查返回它。或者

你也可以尝试:

1.点击下拉菜单的右上角 - 选择数据源。

2.选择新数据源。

3.选择对象。

4.选择你的BLL课程。

5.配置设置。

Yours Farhad。
Hi Your Error is on ddlitems.DataSource = B.GetItemNames();
check what return it.or
you can Try it too:
1.Click on top right of dropdown -Choose Data source.
2.Select New Data Source.
3.Select Object.
4.Select your BLL class.
5.Configure setting.
Yours Farhad.


如果使用ADO.NET连接到数据库,Dropdown sholud将按以下方式绑定。



The Dropdown sholud be binded in the following manner if you are connecting to the database using ADO.NET.

public void ddlbind()
       {
           BALBillDetails B = new BALBillDetails();
           DataSet ds = B.GetItemNames();
           ddlitems.DataSource = ds.Tables[0];
           ddlitems.DataTextField = "Item_Name";
           ddlitems.DataValueField = "Item_Code";
           ddlitems.DataBind();
 
       }


这篇关于下拉列表选择的值不是选中的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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