DropDownList selectvalue

  • Thread starter Thread starter Hei
  • Start date Start date
H

Hei

hi,

i using follow code to provide selection in a DropDownList , but it always
return first item value for every selected item after click submit button.
is it about postback problem?

ddlClientName.DataSource = objcommand.ExecuteReader
ddlClientName.DataValueField = "ID"
ddlClientName.DataTextField = "Name"
ddlClientName.DataBind()

hei
 
Hi,

put the code in question inside IsPostBack check.

If Not Page.IsPostBack Then
'...
ddlClientName.DataSource = objcommand.ExecuteReader
ddlClientName.DataValueField = "ID"
ddlClientName.DataTextField = "Name"
ddlClientName.DataBind()
End if

If the databinding code isn't inside IsPostBack check, DropDownList will be
databound on every request.This causes the effect you mentioned that
selections are not preserved between postbacks
 
problem fixed. thx.

Teemu Keiski said:
Hi,

put the code in question inside IsPostBack check.

If Not Page.IsPostBack Then
'...
ddlClientName.DataSource = objcommand.ExecuteReader
ddlClientName.DataValueField = "ID"
ddlClientName.DataTextField = "Name"
ddlClientName.DataBind()
End if

If the databinding code isn't inside IsPostBack check, DropDownList will be
databound on every request.This causes the effect you mentioned that
selections are not preserved between postbacks
 
Back
Top