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">
</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.
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 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.Formas: