Drop down question

M

Me LK

I have a nested dropdown inside a datagrid. One for colors one for
sizes. Not all items have colors or sizes, however, so I need to find
a way to detect if the drop down is blank and make the control not
visible. If there is a value then I need to add a choose a size. I am
having no problem with the choose a size being added to the control.
It just does not recognize when the value is null or blank. The
control is still visible.

Dim myDataGridITem As DataGridItem

For Each myDataGridITem In itemInfo.Items

Dim ddlPsize As DropDownList
ddlPsize = (myDataGridITem.FindControl("ddlsizes"))

If ddlPsize.DataTextField Is GetType(DBNull) Then
ddlcolors.Visible = False

Else

ddlPsize.Items.Insert(0, "Choose a Size")
End If
Next
 
B

Barrie Wilson

a little hard to follow what you're iterating here but, from what I think I
get of it, it seems to me your table of "items" should probably have a
column (or two) that indicates whether or not color and size are attributes
of the item ... of course you can test these values and then respond
accordingly on the DDList(s)

the other thought I have: why don't you test for "ddlPsize.Items.Count < 1"
rather than "ddlPsize.DataTextField Is GetType(DBNull)" ?

and the logic looks puzzling: if there's no color, then you choose a size ..
and vice-versa; doesn't sound right ....
 
M

Me LK

Thanks your answer worked.

I also found an error in my code regarding size and color as you
noticed.

If ddlPsize.DataTextField Is GetType(DBNull) Then
ddlcolors.Visible = False

should have read

If ddlPsize.DataTextField Is GetType(DBNull) Then
ddlPsize.Visible = False

I have the same coding for both size AND color not one OR the other.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top