View Single Post
  #4 (permalink)  
Old August 5th, 2004, 01:40 PM
fitchic77 fitchic77 is offline
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to fitchic77
Default

Here is the solution when you click on a checkbox it will highlight the row. You can change the colors to your liking in the .aspx file (the four lines of code prior to the "COLUMN" heading). Conversely, when you uncheck the rows, it will conver the colors back to what you set originally.

.aspx
=====================
<div align="center">
    <asp:Label ID="lblStatus" Font-Name="verdana" Font-Size="12px" ForeColor="#ff0000" Runat="server" />
</div>
<ASP:DATAGRID id="MyDataGrid" runat="server" AutoGenerateColumns="false" HeaderStyle-Font-Size="7pt" HeaderStyle-Font-Bold="True" HeaderStyle-BackColor="#afd9e9" Font-Size="7pt" Font-Name="Verdana" ForeColor="#082083" CellSpacing="1" CellPadding="1" BorderWidth="1" BorderColor="white">
    <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#2262BA"></SelectedItemStyle>
    <ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="#082083" BackColor="#afd9e9"></HeaderStyle>
    <FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
    <Columns>
        <asp:TemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="Document" HeaderStyle-Width="270px">
            <ItemTemplate>
                <asp:TextBox id=Document style="TEXT-ALIGN: left; font-size: 8pt" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Document") %>' Width="270px" />
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="Description" HeaderStyle-Width="380px">
            <ItemTemplate>
                <asp:TextBox id="Description" style="TEXT-ALIGN: left; font-size: 8pt" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>' Width="380px" />
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="Add" HeaderStyle-Width="350px">
            <ItemTemplate>
                <asp:Checkbox ID="chkSelected" Runat="server" OnCheckedChanged="highlight_row_CheckedChanged" AutoPostBack="true" />
                <asp:Label ID="txtDocumentID" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "Document") %>' Runat=server />
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>
</ASP:DATAGRID>
<br>
<br>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
    <tr>
        <td align="right">
            <table width="20%" id="Table3" cellSpacing="2" cellPadding="2" border="0">
                <tr>
                    <td align="right"><asp:Button id="cmdNew" runat="server" Width="48px" Text="New" class="button"></asp:Button></td>
                    <td align="right"><asp:Button id="cmdOK" runat="server" Text="Ok" Width="48px" class="button"></asp:Button></td>
                    <td align="right"><asp:Button id="cmdCancel" runat="server" Width="58px" Text="Cancel" class="button"></asp:Button></td>
                    <td align="right"><asp:Button id="cmdHelp" runat="server" Width="48px" Text="Help" class="button"></asp:Button></td>
                </tr>
            </table>
        </td>
    </tr>
</table>

.aspx.vb (code behind):
================================================== =======
    Public Sub highlight_row_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim chkTemp As CheckBox = CType(sender, CheckBox)
        Dim dgi As DataGridItem
        dgi = CType(chkTemp.Parent.Parent, DataGridItem)
        If (chkTemp.Checked) Then
            dgi.BackColor = MyDataGrid.SelectedItemStyle.BackColor
            dgi.ForeColor = MyDataGrid.SelectedItemStyle.ForeColor

        Else
            dgi.BackColor = MyDataGrid.ItemStyle.BackColor
            dgi.ForeColor = MyDataGrid.ItemStyle.ForeColor
        End If
    End Sub

Last edited by fitchic77; October 16th, 2010 at 11:20 AM..
Reply With Quote