ASP.net change color of ASP.net GridView template textbox when value changed

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

I have 30 template textbox columns in an ASP.net GridView, some of which are shown in the code below. If any text is changed
in these textboxes I want to change the background color of the textbox . What VB.net code would I use to do this?

Thanks

     <asp:TemplateField HeaderText="D1" Visible="false">
                           <ItemTemplate>
                                <asp:Textbox ID="D1" runat="server"  Visible="true" Width="20"></asp:Textbox>
                           </ItemTemplate>
                      </asp:TemplateField>
                      <asp:TemplateField HeaderText="D2" Visible="false">
                           <ItemTemplate>
                                <asp:Textbox ID="D2" runat="server"  Visible="true" Width="20" ></asp:Textbox>
                           </ItemTemplate>
                      </asp:TemplateField>
                     <asp:TemplateField HeaderText="D3" Visible="false">
                           <ItemTemplate>
                                <asp:Textbox ID="D3" runat="server"  Visible="true" Width="20" ></asp:Textbox>
                           </ItemTemplate>
                      </asp:TemplateField>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Actuall you don't need server side processing for such processing. You could do it with client side javasctipt:
<html xmlns="XHTML namespace"> 
<head runat="server">
 
      <title>Untitled Page</title>
      <script type="text/javascript">
               function keyUP(txt)
               {
    if (txt.value == "") {
        txt.style.backgroundColor = "";
    }
    else{
        txt.style.backgroundColor = "yellow";
    }
               }
      </script>
</head>
 
<body>
<form id="form1" runat="server"> 
		     <asp:TemplateField HeaderText="D1" Visible="false">
                           <ItemTemplate>
                                <asp:Textbox ID="D1" onkeyup="keyUP(this)" runat="server"  Visible="true" Width="20"></asp:Textbox>
                           </ItemTemplate>
                      </asp:TemplateField>
                      <asp:TemplateField HeaderText="D2" Visible="false">
                           <ItemTemplate>
                                <asp:Textbox ID="D2" onkeyup="keyUP(this)" runat="server"  Visible="true" Width="20" ></asp:Textbox>
                           </ItemTemplate>
                      </asp:TemplateField>
                     <asp:TemplateField HeaderText="D3" Visible="false">
                           <ItemTemplate>
                                <asp:Textbox ID="D3" onkeyup="keyUP(this)" runat="server"  Visible="true" Width="20" ></asp:Textbox>
                           </ItemTemplate>
                      </asp:TemplateField>
</form>
</body>
 
</html>

Open in new window

Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks very much

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