Groups | Blog | Home
all groups > asp.net > january 2004 >

asp.net : DropDownList selectvalue



Teemu Keiski
1/4/2004 3:38:20 PM
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

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

[quoted text, click to view]

Hei
1/4/2004 9:31:30 PM
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

Hei
1/4/2004 11:48:42 PM
problem fixed. thx.

[quoted text, click to view]

AddThis Social Bookmark Button