473,769 Members | 6,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

e.Item.BackColo r /highlight rows

LU
A)I build a datagrid based on a calendar date selection.
B)When user clicks a button column on the datagrid I want to highlight this
row. I use the code below to highlight the row.

***** CODE TO HIGHLIGHT ROW
Sub Datagrid_ItemCo mmand(ByVal s As Object, ByVal e As
DataGridCommand EventArgs)

If e.CommandName = "ViewUnitReques t" Then
e.Item.BackColo r = System.Drawing. Color.LightGray
end if
End Sub
*****
C)This works and the row clicked is highlighted.
D)Problem is if user clicks a different row, the old row stays highlighted
and the new row is highlighted.
E)How do I make sure the old row is back to normal color?
F)Do I need to rebind the datagrid before i change the color?
Thank you
Nov 19 '05 #1
6 3441
You may just want to set the style to a different color on the item selected
event.
directly you can do this in vs.net net by rightclicking on the datagrid and
selecting property builder then format, Item Selected.

or in html:
<SelectedItemSt yle BackColor="Gree n"></SelectedItemSty le> will do it
"LU" wrote:
A)I build a datagrid based on a calendar date selection.
B)When user clicks a button column on the datagrid I want to highlight this
row. I use the code below to highlight the row.

***** CODE TO HIGHLIGHT ROW
Sub Datagrid_ItemCo mmand(ByVal s As Object, ByVal e As
DataGridCommand EventArgs)

If e.CommandName = "ViewUnitReques t" Then
e.Item.BackColo r = System.Drawing. Color.LightGray
end if
End Sub
*****
C)This works and the row clicked is highlighted.
D)Problem is if user clicks a different row, the old row stays highlighted
and the new row is highlighted.
E)How do I make sure the old row is back to normal color?
F)Do I need to rebind the datagrid before i change the color?
Thank you

Nov 19 '05 #2
last post may not have been sent:
<SelectedItemSt yle BackColor="Gree n"></SelectedItemSty le> will work

"LU" wrote:
A)I build a datagrid based on a calendar date selection.
B)When user clicks a button column on the datagrid I want to highlight this
row. I use the code below to highlight the row.

***** CODE TO HIGHLIGHT ROW
Sub Datagrid_ItemCo mmand(ByVal s As Object, ByVal e As
DataGridCommand EventArgs)

If e.CommandName = "ViewUnitReques t" Then
e.Item.BackColo r = System.Drawing. Color.LightGray
end if
End Sub
*****
C)This works and the row clicked is highlighted.
D)Problem is if user clicks a different row, the old row stays highlighted
and the new row is highlighted.
E)How do I make sure the old row is back to normal color?
F)Do I need to rebind the datagrid before i change the color?
Thank you

Nov 19 '05 #3
LU
I did change this in VS.net, but it didn't work. Does it have anything to do
with viewstate?

"Kurt Schroeder" wrote:
last post may not have been sent:
<SelectedItemSt yle BackColor="Gree n"></SelectedItemSty le> will work

"LU" wrote:
A)I build a datagrid based on a calendar date selection.
B)When user clicks a button column on the datagrid I want to highlight this
row. I use the code below to highlight the row.

***** CODE TO HIGHLIGHT ROW
Sub Datagrid_ItemCo mmand(ByVal s As Object, ByVal e As
DataGridCommand EventArgs)

If e.CommandName = "ViewUnitReques t" Then
e.Item.BackColo r = System.Drawing. Color.LightGray
end if
End Sub
*****
C)This works and the row clicked is highlighted.
D)Problem is if user clicks a different row, the old row stays highlighted
and the new row is highlighted.
E)How do I make sure the old row is back to normal color?
F)Do I need to rebind the datagrid before i change the color?
Thank you

Nov 19 '05 #4
LU
Here is the top portion of one of the datagrids
<asp:DataGrid id="PrivateDuty AssigDG" Runat="Server"
AutoGenerateCol umns="False" OnItemCommand=" NurseAssig_Item Command"
CellSpacing="1" width="100%" GridLines="None " Cellpadding="3"
HeaderStyle-BackColor="#99C CCC"
AlternatingItem Style-BackColor="#e3f 2f2" ItemStyle-BackColor="#DED FDE"
DataKeyField="P NID">
<SelectedItemSt yle BackColor="Gray "></SelectedItemSty le>
<EditItemStyl e Font-Names="arial;ve rdana"></EditItemStyle>
<AlternatingIte mStyle Font-Size="11px" Font-Names="Arial;Ve rdana"
BackColor="#E3F 2F2"></AlternatingItem Style>
<ItemStyle Font-Size="11px" Font-Names="arial;ve rdana"
BackColor="Whit e"></ItemStyle>
<HeaderStyle Font-Size="11px" Font-Names="arial;" Font-Bold="True"
ForeColor="Blac k" BackColor="#99C CCC"></HeaderStyle>
<Columns>
<asp:BoundColum n DataField="URPN AID" ReadOnly="True"
HeaderText="Ass ignmentID"></asp:BoundColumn >
<asp:BoundColum n DataField="PNID " ReadOnly="True"
HeaderText="Nur sesSysID"></asp:BoundColumn >
<asp:TemplateCo lumn>
<HeaderTemplate >
"Kurt Schroeder" wrote:
last post may not have been sent:
<SelectedItemSt yle BackColor="Gree n"></SelectedItemSty le> will work

"LU" wrote:
A)I build a datagrid based on a calendar date selection.
B)When user clicks a button column on the datagrid I want to highlight this
row. I use the code below to highlight the row.

***** CODE TO HIGHLIGHT ROW
Sub Datagrid_ItemCo mmand(ByVal s As Object, ByVal e As
DataGridCommand EventArgs)

If e.CommandName = "ViewUnitReques t" Then
e.Item.BackColo r = System.Drawing. Color.LightGray
end if
End Sub
*****
C)This works and the row clicked is highlighted.
D)Problem is if user clicks a different row, the old row stays highlighted
and the new row is highlighted.
E)How do I make sure the old row is back to normal color?
F)Do I need to rebind the datagrid before i change the color?
Thank you

Nov 19 '05 #5
What are you using the button column for? Are you using it only to
highlight the row? If so, why not eliminate round trips to the server and
implement the functionality on the client side using JavaScript and CSS?

HTH
----------------
Dave Fancher
http://davefancher.blogspot.com
Nov 19 '05 #6
Hi,
I noticed you are overriding the OnItemCommand with:
OnItemCommand=" NurseAssig_Item Command"
you could use the PrivateDutyAssi gDG_ItemCommand that will be created with
studio. I truiedturning view state off and loading the grid on post back and
i still get a highlight. Here is a simple example that worked for me:

<form id="Form1" method="post" runat="server">
<asp:DataGrid id=dgAuthors style="Z-INDEX: 101; LEFT: 216px; POSITION:
absolute; TOP: 128px" runat="server" DataSource="<%# DsAuthors1 %>"
DataKeyField="a u_id" DataMember="aut hors" AutoGenerateCol umns="False"
EnableViewState ="False">
<SelectedItemSt yle BackColor="#CCC C99"></SelectedItemSty le>
<AlternatingIte mStyle BackColor="Silv er"></AlternatingItem Style>
<Columns>
<asp:ButtonColu mn Text="hi Lite" HeaderText="hi lite"
CommandName="Se lect"></asp:ButtonColum n>
<asp:BoundColum n DataField="au_i d" SortExpression= "au_id"
ReadOnly="True" HeaderText="au_ id"></asp:BoundColumn >
<asp:BoundColum n DataField="au_l name" SortExpression= "au_lname"
HeaderText="au_ lname"></asp:BoundColumn >
<asp:BoundColum n DataField="au_f name" SortExpression= "au_fname"
HeaderText="au_ fname"></asp:BoundColumn >
<asp:BoundColum n DataField="au_f name" SortExpression= "au_fname"
HeaderText="au_ fname"></asp:BoundColumn >
</Columns>
</asp:DataGrid>
</form>
1. I created a sqldataadapter off ofthe authors table on northwinds
2. added a dataset called dsauthors and an instance of it (dsAuthors1)
3. i filled the dataset on load.
this is the only code i added to get this running:
If Not IsPostBack Then
SqlDataAdapter1 .Fill(DsAuthors 1)
dgAuthors.DataB ind()
End If
I can give you the full example if you like.
I had a lot of frustration with vs.net so i understand it is not as
intuitive as everyone says. "Emperror's new cloths"! however, it does work if
you work withit.
I hope this helps
please let me know!!!
kes

"LU" wrote:
Here is the top portion of one of the datagrids
<asp:DataGrid id="PrivateDuty AssigDG" Runat="Server"
AutoGenerateCol umns="False" OnItemCommand=" NurseAssig_Item Command"
CellSpacing="1" width="100%" GridLines="None " Cellpadding="3"
HeaderStyle-BackColor="#99C CCC"
AlternatingItem Style-BackColor="#e3f 2f2" ItemStyle-BackColor="#DED FDE"
DataKeyField="P NID">
<SelectedItemSt yle BackColor="Gray "></SelectedItemSty le>
<EditItemStyl e Font-Names="arial;ve rdana"></EditItemStyle>
<AlternatingIte mStyle Font-Size="11px" Font-Names="Arial;Ve rdana"
BackColor="#E3F 2F2"></AlternatingItem Style>
<ItemStyle Font-Size="11px" Font-Names="arial;ve rdana"
BackColor="Whit e"></ItemStyle>
<HeaderStyle Font-Size="11px" Font-Names="arial;" Font-Bold="True"
ForeColor="Blac k" BackColor="#99C CCC"></HeaderStyle>
<Columns>
<asp:BoundColum n DataField="URPN AID" ReadOnly="True"
HeaderText="Ass ignmentID"></asp:BoundColumn >
<asp:BoundColum n DataField="PNID " ReadOnly="True"
HeaderText="Nur sesSysID"></asp:BoundColumn >
<asp:TemplateCo lumn>
<HeaderTemplate >
"Kurt Schroeder" wrote:
last post may not have been sent:
<SelectedItemSt yle BackColor="Gree n"></SelectedItemSty le> will work

"LU" wrote:
A)I build a datagrid based on a calendar date selection.
B)When user clicks a button column on the datagrid I want to highlight this
row. I use the code below to highlight the row.

***** CODE TO HIGHLIGHT ROW
Sub Datagrid_ItemCo mmand(ByVal s As Object, ByVal e As
DataGridCommand EventArgs)

If e.CommandName = "ViewUnitReques t" Then
e.Item.BackColo r = System.Drawing. Color.LightGray
end if
End Sub
*****
C)This works and the row clicked is highlighted.
D)Problem is if user clicks a different row, the old row stays highlighted
and the new row is highlighted.
E)How do I make sure the old row is back to normal color?
F)Do I need to rebind the datagrid before i change the color?
Thank you

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4612
by: Stanley J Mroczek | last post by:
I am loading the 5 checkboxlist from a database. I have 5 lists. The first four are interior, exterior, safety and drive train. The fifth is optional options. It is possible the optional option was already selected, if it was selected it would be in one of the first four (interior, exterior, safety and drive train). What I am doing is loading the fifth checkboxlist and then checking to see if it was selected if so, I am trying to remove it...
1
5334
by: john woo | last post by:
Hi I'm not good at JS, but want to get more about it. I want to use a JSP (the java code just used to get date, the rest are html and javascript), to display a table. the requirement is the all rows in even number in light-blue, rows in odd number in light gray, when a mouse clicks on a row, this row gets highlighted and in yellow, and it keeps highlighted
1
2693
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting, paginantion or accepting the add and remove item events. What i am observing is that none of the vents are happening... (Sort, page, or item). I am sure I am missing something basic here... Need help... Thanks much
9
2695
by: Max Weebler | last post by:
Hi, I have a datagrid built that has an alternating item style that sets the backcolor and ForeColor of its rows. I have 4 template columns. One of them has a LinkButton embedded in it to perform updates. All the styles that are set are being followed by all templated columns with the exception for the update column. The update column does set the BackColor appropriately but when setting its ForeColor the LinkButton's color is blue and...
1
2874
by: Anup | last post by:
Hi Group, I have a datagrid with dropdown in my application. I want to fill the data in dropdown by an ArrayList for that I am using "e.Item.FindControl("DropdownId")" but this function is returning NULL THUS I m getting exception "Object Refrence not set to an Instance to Object", Here is the code I wrote (ASP.NET 1.1)...
3
3013
by: almurph | last post by:
Hi, I'm a newbie to Javascript. I can;t even finf a full API for it! Anyway I have a table structure and when a user presses the down-arrow button the item in said table is meant to be highlighted. Here is the code that I have so far: document.getElementById('tableID').style.backgroundColor ="#000000"; document.getElementById('tableID').setAttribute ("border", 2);
1
1376
by: Se0ng | last post by:
hi, I'm new to vb.net and I need some help, I done a backcolor change to my list view item as below code, Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click objItem = lvMedic.Items.Add("cb034") With objItem .SubItems.Add("Saliva Glukosa") .SubItems.Add("Lotion") .SubItems.Add("20.00")
3
29319
by: CSharper | last post by:
Is it possible to selectivly change the color of an item in text. I saw ForeColor option, but it changes the color of all the items. If it is not possible, is there any other control list listbox where we can see more than one item and change the color during run time. Thanks.
1
6748
by: rogerford | last post by:
I have a grid which i bind with values from Database. I have events to edit and update the grid. I am not using SqlDatasource to connect to DB. Rather i am doing the updating of the grid Programmatically. I have 3 columns, LID(item template column) ,LVal (Edit Item template column) and Edit link My Question: 1) My EditITemTemplate column has a textbox txt_Lval which does not show up on the page load. But if click on edit link that...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.