1
  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();
3
  • paste some more code from HTML section too so that we can go for solutions............ Commented Oct 11, 2012 at 4:46
  • Have you selected an item in ddlBanAcc ? If you dont s.Split will fail. Commented Oct 11, 2012 at 4:49
  • yes i do select an item in ddlBanAcc Commented Oct 11, 2012 at 4:49

4 Answers 4

11

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]
Sign up to request clarification or add additional context in comments.

Comments

3
    <asp:DropDownList ID="ddlBanAcc" runat="server" DataTextField="" DataValueField="">
    </asp:DropDownList>

Try defining the DataTextField and DataValueField in the back end. This should help.

9 Comments

Give your respective DataTextField and DataValueField
Yes have seen try giving DataValueField also
i cant specify a DataValue field as in am concatenating the values and no specific column is being used to populate the Dropdownlist
For you using SelectedValue. So you need to have DataFieldValue
I have specified CONCATE as my DataValueField it still doesnt work
|
1

You'll need to add AutoPostBack="true" to your DropDownList to get it to post back. I presume this is why the code is not executing.

1 Comment

No still not getting any values
0

There is one more surprising issue that can cause this! My list values came from a database and the values had linefeed and carriage return: "\r\n". These values look like an innocent space, but actually they are not! My solution was to remove these hidden Char values. Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.