Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
| Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2004, 11:30 AM
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 datagrid w/checkbox highlight row onchange

I need to highlight a row once I've clicked on a checbox...

Anbody have any ideas?

Last edited by fitchic77; October 16th, 2010 at 11:20 AM..
 
Old August 5th, 2004, 12:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Select the row by setting the SelectedIndex of the datagrid, or of the DataGridItem.

Brian
 
Old August 5th, 2004, 12:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Oh, this requires style information setup for the SelectedItem template.

Brian
 
Old August 5th, 2004, 01:40 PM
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..




Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting a GridView Row to highlight gcm_uk ASP.NET 2.0 Basics 0 May 1st, 2007 05:55 AM
Print the row of datagrid with checkbox with check niks_crasher VS.NET 2002/2003 0 September 2nd, 2006 03:45 AM
how delete row in datagrid which check checkbox ashish2001mca Forum and Wrox.com Feedback 1 September 18th, 2005 03:43 AM
Row highlight with mousemove hello2lu Access VBA 0 July 14th, 2004 04:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.