Home All Groups Group Topic Archive Search About

DataGrid item dropdownlist javascript disable

Author
2 Apr 2006 7:58 PM
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.

Author
2 Apr 2006 10:08 PM
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%>' 
Show quoteHide quote
"bnlockw***@gmail.com" wrote:

> 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.
>
>