473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

e.Item.BackColor /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_ItemCommand(ByVal s As Object, ByVal e As
DataGridCommandEventArgs)

If e.CommandName = "ViewUnitRequest" Then
e.Item.BackColor = 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 3404
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:
<SelectedItemStyle BackColor="Green"></SelectedItemStyle> 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_ItemCommand(ByVal s As Object, ByVal e As
DataGridCommandEventArgs)

If e.CommandName = "ViewUnitRequest" Then
e.Item.BackColor = 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:
<SelectedItemStyle BackColor="Green"></SelectedItemStyle> 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_ItemCommand(ByVal s As Object, ByVal e As
DataGridCommandEventArgs)

If e.CommandName = "ViewUnitRequest" Then
e.Item.BackColor = 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:
<SelectedItemStyle BackColor="Green"></SelectedItemStyle> 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_ItemCommand(ByVal s As Object, ByVal e As
DataGridCommandEventArgs)

If e.CommandName = "ViewUnitRequest" Then
e.Item.BackColor = 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="PrivateDutyAssigDG" Runat="Server"
AutoGenerateColumns="False" OnItemCommand="NurseAssig_ItemCommand"
CellSpacing="1" width="100%" GridLines="None" Cellpadding="3"
HeaderStyle-BackColor="#99CCCC"
AlternatingItemStyle-BackColor="#e3f2f2" ItemStyle-BackColor="#DEDFDE"
DataKeyField="PNID">
<SelectedItemStyle BackColor="Gray"></SelectedItemStyle>
<EditItemStyle Font-Names="arial;verdana"></EditItemStyle>
<AlternatingItemStyle Font-Size="11px" Font-Names="Arial;Verdana"
BackColor="#E3F2F2"></AlternatingItemStyle>
<ItemStyle Font-Size="11px" Font-Names="arial;verdana"
BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="11px" Font-Names="arial;" Font-Bold="True"
ForeColor="Black" BackColor="#99CCCC"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="URPNAID" ReadOnly="True"
HeaderText="AssignmentID"></asp:BoundColumn>
<asp:BoundColumn DataField="PNID" ReadOnly="True"
HeaderText="NursesSysID"></asp:BoundColumn>
<asp:TemplateColumn>
<HeaderTemplate>
"Kurt Schroeder" wrote:
last post may not have been sent:
<SelectedItemStyle BackColor="Green"></SelectedItemStyle> 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_ItemCommand(ByVal s As Object, ByVal e As
DataGridCommandEventArgs)

If e.CommandName = "ViewUnitRequest" Then
e.Item.BackColor = 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_ItemCommand"
you could use the PrivateDutyAssigDG_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="au_id" DataMember="authors" AutoGenerateColumns="False"
EnableViewState="False">
<SelectedItemStyle BackColor="#CCCC99"></SelectedItemStyle>
<AlternatingItemStyle BackColor="Silver"></AlternatingItemStyle>
<Columns>
<asp:ButtonColumn Text="hi Lite" HeaderText="hi lite"
CommandName="Select"></asp:ButtonColumn>
<asp:BoundColumn DataField="au_id" SortExpression="au_id"
ReadOnly="True" HeaderText="au_id"></asp:BoundColumn>
<asp:BoundColumn DataField="au_lname" SortExpression="au_lname"
HeaderText="au_lname"></asp:BoundColumn>
<asp:BoundColumn DataField="au_fname" SortExpression="au_fname"
HeaderText="au_fname"></asp:BoundColumn>
<asp:BoundColumn DataField="au_fname" 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(DsAuthors1)
dgAuthors.DataBind()
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="PrivateDutyAssigDG" Runat="Server"
AutoGenerateColumns="False" OnItemCommand="NurseAssig_ItemCommand"
CellSpacing="1" width="100%" GridLines="None" Cellpadding="3"
HeaderStyle-BackColor="#99CCCC"
AlternatingItemStyle-BackColor="#e3f2f2" ItemStyle-BackColor="#DEDFDE"
DataKeyField="PNID">
<SelectedItemStyle BackColor="Gray"></SelectedItemStyle>
<EditItemStyle Font-Names="arial;verdana"></EditItemStyle>
<AlternatingItemStyle Font-Size="11px" Font-Names="Arial;Verdana"
BackColor="#E3F2F2"></AlternatingItemStyle>
<ItemStyle Font-Size="11px" Font-Names="arial;verdana"
BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="11px" Font-Names="arial;" Font-Bold="True"
ForeColor="Black" BackColor="#99CCCC"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="URPNAID" ReadOnly="True"
HeaderText="AssignmentID"></asp:BoundColumn>
<asp:BoundColumn DataField="PNID" ReadOnly="True"
HeaderText="NursesSysID"></asp:BoundColumn>
<asp:TemplateColumn>
<HeaderTemplate>
"Kurt Schroeder" wrote:
last post may not have been sent:
<SelectedItemStyle BackColor="Green"></SelectedItemStyle> 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_ItemCommand(ByVal s As Object, ByVal e As
DataGridCommandEventArgs)

If e.CommandName = "ViewUnitRequest" Then
e.Item.BackColor = 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
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...
1
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...
1
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,...
9
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...
1
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...
3
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...
1
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)...
3
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...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.