Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Checkbox and Background Color Change within a  Datagrid.

Posted on 2006-06-22
3
Medium Priority
?
721 Views
Last Modified: 2012-05-05
I have seen a few articles on how to change the background color of a row within a datagrid by clicking a button but I need to do the opposite.

I would like to highlight the background of a row and put a checkmark in the checkbox within the row of a datagrid when the user clicks on any of the cells within that row.

Can anybody give me some direction on how to accomplish this?

I would like to use CSS and JS if possible. The datagrid I have is being populated by a database call.

Here is some code I have so far.

the javascript function for the checkbox:
---------------------------------------------------------------------------
function SelectAllCheckboxes(spanChk)
{
      // Added as ASPX uses SPAN for checkbox
      var oItem = spanChk.children;
      var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
      xState=theBox.checked;

      elm=theBox.form.elements;
      for(i=0;i<elm.length;i++)
      if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
      {
            if(elm[i].checked!=xState)
            elm[i].click();
      }
}                  
------------------------------------------------------------------------------------------

the datagrid in html:
-------------------------------------------------------------------------------
<asp:datagrid id="dgCustomFindResults" runat="server" EnableViewState="True" AutoGenerateColumns="True"
      ShowHeader="True" Font-Name="Arial" Font-Size="8pt" HorizontalAlign="Left" Width="900">
      <Columns>
            <asp:TemplateColumn HeaderText="">
                  <HeaderTemplate>
                        <asp:CheckBox onclick="javascript:SelectAllCheckboxes(this);" id="chkAll" runat="server"></asp:CheckBox>
                  </HeaderTemplate>
                  <ItemTemplate>
                        <asp:CheckBox ID="myCheckbox" EnableViewState="False" AutoPostBack="False" Runat="server" />
                  </ItemTemplate>
            </asp:TemplateColumn>
      </Columns>
</asp:datagrid>
----------------------------------------------------------------------------------


the SQL to get data:
--------------------------------------------------------------------------------------------------
      SqlDataAdapter da = new SqlDataAdapter ( cmdObj ) ;
      DataSet dsMLS = new DataSet("MLS");
      da.SelectCommand.CommandTimeout = 0;
      da.Fill(dsMLS, "MLS");
      dgCustomFindResults.DataSource =  dsMLS.Tables["MLS"].DefaultView;
      dgCustomFindResults.DataBind();
---------------------------------------------------------------------------------------------------

I add a checkbox at the first column and get the results like so:

       -----------------------------------------------------------------------------------------
       chkbox |  account_number  | date_sold  | county_name  | sale_price  |   etc...
       -------------------------------------------------------------------------------------------
 
I would like the ablility to have the user click on any cell and then to highlight that row and also
put a check mark in the checkbox.

The row should stay highlighted as long as the checkbox is checked. If the row is clicked again
then the checkbox should be unchecked and the highlight should disappear.

There is no need for a postback since I want to keep the data the same.

Please let me know if someone can help with a solution.

-Eddie


0
Comment
Question by:FastEddie___
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
Agarici earned 2000 total points
ID: 16967510
see this link:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q745q

there is a "How do I color a individual cell depending upon its value or some external method?"

see if it helps.

A.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question