下拉列表中不选择价值asp.net [英] Dropdown list not selecting value asp.net

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

问题描述

  ddlBanAcc.Items.Insert(0,新的ListItem(,));
  字符串s = ddlBanAcc.SelectedValue;
  字符串[]字=​​ s.Split('|');
  如果(ddlBanAcc.SelectedIndex→1)
  {
    查询+ =和DtaLineAccountToDebit ='+字[0] +';
  }

在ddlBankAcc(DROPDOWNLIST选择)本人填充DataGrid这是更新面板中

然而,code未执行,没有价值越来越被这句话选定 ddlBanAcc.SelectedValue;

编辑:HTML code

 < TD align =leftVALIGN =顶>
                            &安培; NBSP;< / TD>
                 &所述; TD>
                            银行账户:
                        < / TD>
                        &所述; TD>
 < ASP:DropDownList的=服务器ID =ddlBanAccWIDTH =160像素TaEvalex =3>
    < / ASP:DropDownList的>                        < / TD>

编辑:怎么我在ddlBanAcc添加数据

 的DataTable dtbankaccount = oDBAccess.getDataTable(SELECT BkiAccountNb +'|'+ BkiCurrency +'|'+ BkiAccountNb AS CONCATE从VwCieBankAcc);
    ddlBanAcc.DataTextField =CONCATE;
    ddlBanAcc.DataSource = dtbankaccount;    ddlBanAcc.DataBind();


解决方案

您需要检查的IsPostBack,如果它不做的DataBind,因为这使得DropDownList中重新得到他的全部价值,而失去选择

 如果(!的IsPostBack)
    ddlBanAcc.DataBind();

贝斯上DropDownList的是保持ViewState中他的价值观,你需要使用的IsPostBack到满的过程也就是填写并最终code将是:

 如果(!的IsPostBack)
{
    数据表dtbankaccount = oDBAccess.getDataTable(SELECT BkiAccountNb +'|'+ BkiCurrency +'|'+ BkiAccountNb AS CONCATE从VwCieBankAcc);
    ddlBanAcc.DataTextField =CONCATE;
    ddlBanAcc.DataSource = dtbankaccount;    ddlBanAcc.DataBind();
}

如果您需要做的DataBind,甚至他的选择后更改DropDownList中的内容,任何其他原因,你可以使用总是得到后回值的Request.Form 如:

 的Request.Form [DromDownListID.UniqueID]

  ddlBanAcc.Items.Insert(0, new ListItem("", ""));
  string s = ddlBanAcc.SelectedValue;
  string[] words = s.Split('|');
  if (ddlBanAcc.SelectedIndex > 1)
  {
    query += "'and DtaLineAccountToDebit='" + words[0] + "'";
  }

On the ddlBankAcc (Dropdownlist selection) i am populating the Datagrid which is in the Update Panel

However the code is not executing and no value is getting selected by this statement ddlBanAcc.SelectedValue;

EDIT: HTML CODE

<td align="left" valign="top">
                            &nbsp;</td>
                 <td>
                            Bank Account:
                        </td>
                        <td>
 <asp:DropDownList runat="server" ID="ddlBanAcc" Width="160px" TaEvalex="3">
    </asp:DropDownList>

                        </td>

EDIT : how i am adding data in ddlBanAcc

DataTable dtbankaccount = oDBAccess.getDataTable("SELECT BkiAccountNb + ' | ' + BkiCurrency+ ' | ' +BkiAccountNb AS CONCATE  From VwCieBankAcc");
    ddlBanAcc.DataTextField = "CONCATE";
    ddlBanAcc.DataSource = dtbankaccount;

    ddlBanAcc.DataBind();

解决方案

You need to check IsPostBack, and if it is do not make DataBind, because this is making the DropDownList to re-get all his values, and lost the selection.

if(!IsPostBack)
    ddlBanAcc.DataBind();

Especial on DropDownList that is keep his values on ViewState you need to use the IsPostBack to the full process that is fill in. And the final code will be:

if(!IsPostBack)
{
    DataTable dtbankaccount = oDBAccess.getDataTable("SELECT BkiAccountNb + ' | ' + BkiCurrency+ ' | ' +BkiAccountNb AS CONCATE  From VwCieBankAcc");
    ddlBanAcc.DataTextField = "CONCATE";
    ddlBanAcc.DataSource = dtbankaccount;

    ddlBanAcc.DataBind();
}

If for any other reason you need to make DataBind and change the content of the DropDownList even after his selection you can always get the post back value using the Request.Form as:

Request.Form[DromDownListID.UniqueID]

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

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