By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,275 Members | 1,927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,275 IT Pros & Developers. It's quick & easy.

e.Item.BackColor /highlight rows

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.