Enable/Disable a Cell based on value of Other Cell

Deepak Lakkad
Deepak Lakkad used Ask the Experts™
on
Hi,

I have a GridView in my WebApplication. Code for the GridView is given below:

<asp:GridView ID="gvSalesOrder" runat="server"
              AutoGenerateColumns="false" Width="100%" 
              DataKeyNames="SOID">
              <HeaderStyle CssClass="header" />
              <Columns>
                <asp:TemplateField HeaderText="Order No">
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkOrderNo" runat="server" Text='<%# Eval("OrderNo") %>' CommandArgument='<%# Bind("SOID") %>' ToolTip="View" CommandName="ViewOrder" CausesValidation="false"></asp:LinkButton>
                    </ItemTemplate>
                    <HeaderStyle />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Order Date">
                    <ItemTemplate>
                        <asp:Label ID="lblOrderDate" runat="server" Text='<%# Eval("OrderDate", "{0:d}") %>'></asp:Label>
                    </ItemTemplate>
                    <HeaderStyle />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="StatusID" Visible = "false">
                    <ItemTemplate>
                        <asp:Label ID="lblStatusID" runat="server" Text='<%# Eval("StatusID") %>'></asp:Label>
                    </ItemTemplate>
                    <HeaderStyle />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Status">
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkStatus" runat="server" Text='<%# Eval("Status") %>' CommandArgument='<%# Bind("SOID") %>' ToolTip="Approve" CommandName="Approve" CausesValidation="false"></asp:LinkButton>
                    </ItemTemplate>
                    <HeaderStyle />
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Open in new window


What I want to do is, I want to enable/disable the Status cell based on the Value of StatusID cell.

I am using Visual Studio 2008, C#.

Thanks in advance

- Deepak Lakkad
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
you can do it in RowCreated
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
 
    {
 
        if (e.Row.DataItem != null)
 
        {
 
            DataRowView drv = (DataRowView)e.Row.DataItem;
 
            string statusID= Convert.ToString(drv["StatusID"]);
 
            if (statusID.Trim() == "Some status")
            {
                 // Retrieve the LinkButton control
                 LinkButton addButton = (LinkButton)e.Row.FindControl("lnkStatus");
       
            }
              /////
        }
 
    }
Top Expert 2011
Commented:
It works, thanks for reply

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial