Hi,
couldn't you run Page.FindControl based on what you have in data reader (do
it when looping the results). By default set Visible = False and when
looping the datareader, if control is found then set it to visible=true
While reader.Read()
Dim ctrl As Control=Page.FindControl(reader.GetString("Control Name"))
ctrl.Visible=True
End While
reader.Close()
If it needs to work in an environment where visibility might change between
postbacks, you probably need to have controls in some sort of array or list
where you would set others (not included in the datareader so set their
visibility to false), or then just loop through all controls on the Page to
hide those others.
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
"Ed Chiu" <> wrote in message
news:7317A5A0-A1F8-46C9-A962-...
> Hi,
>
> Is there a way to set webform controls to visible/invisible dynamically.
> Say
> I have a textbox cann txtFirstName, I know the following statement can set
> it
> visible:
>
> txtFirstName.visible = true
>
> Here is difficult part, I am tring to set the controls visible based on
> the
> content of DataReader or DataSet. If the datareader has a row that has an
> item "txtFirstName" then txtFirstName should be visible.
>
> Sure I can use a big select statement to do this:
>
> select case fieldName
> case "txtFirstName":
> txtFirstName.visible = true
> 'about another 50 case statements follow
> end select
>
> But is there a better way?
>
> TIA
|