DataGrid item dropdownlist javascript disable

B

bnlockwood

Hello all,.
I have a datagrid and one of the columns has a static dropdownlist
which means each column has the exact same dropdownlist. On the c#
side values are pulled from the database and depending on the value
from the db it should either keep the dropdownlist enabled or it should
set it as disabled for that row. I believe some javascript like
document.getElementById would help somehow but I'm still learning.

Eg.
Each row has a color list of:

BROWN
BLUE
ORANGE

if the database says that the row value is null then disable & hide
that column for that row. Meaning that item doesn't need a color.

If someone could help that would be great. Thanks in advance.
 
P

Phillip Williams

You do not need JavaScript. This is all server-side processing since you
have to decide based on the data.

You can use the databinding expression to evaluate the field; if it is not
DBNull then set the Enabled property to true otherwise false, e.g. the
syntax in asp.net 2.0 is:

<asp:DropDownList ID="ddlProducts" runat="server"
Enabled='<%#Eval("Color") <> DBNull.Value%>' >
<asp:ListItem Value="BLUE">Blue</asp:ListItem>
<asp:ListItem Value="BROWN">Brown</asp:ListItem>
<asp:ListItem Value="ORANGE">Orange</asp:ListItem>
</asp:DropDownList>

In ASP.NET 1.1:

Enabled ='<%# DataBinder.Eval(Container.DataItem, "Color") <>
DBNull.Value%>'
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top