Hi Angela,
Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.
Is your DataGrid control WinForm based or Web Form based? Because you
posted in microsoft.public.dotnet.framework.aspnet.webcontrols group, I
suppose your datagrid control is web server control.
Based on my understanding, you want to do some customize with your datagrid
control, such as cursor display, table row highlight.
===============================================
Actually, Asp.Net just encapsulates the Html code, and will the server
controls and classes will render as Html code. So anything html can do,
then asp.net can do it also.
Asp.Net DataGrid control will render as <table> <tr> <td> html tags.
For your specifically questions, some of them asp.net did not give them
server side support, so you need to fulfill them through Client side
javascript code, but you should add the javascript event handler in server
side.(Also, you event can dynamically generate the javascript code at
runtime)
1). To highlight the clicked row in the DataGrid, you need the
"onmousedown" or "onclick" event of <tr> tag
3). To highlight Rows as the cursor passes over them, cursor changes from
arrow to hand, you need the "onmouseover" event of <tr> tag and use
element.style.cursor property.
For your second question of "Be able to click anywhere on a given row", I
am not fully understand. Normally, I suppose you want to high light a
certain <td> when clicked.
This is almost the same with the <tr> tag, but add the event handler at
different server element.
Sample code like this:
Client script code:
<script language="javascript">
var originalrow_color, originalitem_color;
function highlightrow(obj)
{
if(obj.bgColor!="#ff0000")
{
originalrow_color=obj.bgColor;
obj.bgColor="#ff0000";
}
else
{
obj.bgColor=originalrow_color;
}
}
function highlightitem(obj)
{
originalitem_color=obj.bgColor;
obj.bgColor="blue";
}
function changebackcolor(obj)
{
obj.bgColor=originalitem_color;
}
function changecursor(obj)
{
obj.style.cursor="hand";
}
</script>
Server side C# code:
private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataGridItem dgi=e.Item;
if(dgi.ItemType==ListItemType.AlternatingItem)
{
dgi.Attributes.Add("onclick","highlightrow(this)");
dgi.Attributes.Add("onmouseover","changecursor(this)");
TableCell tc=dgi.Cells[1];
tc.Attributes.Add("onmousedown","highlightitem(this)");
tc.Attributes.Add("onmouseup","changebackcolor(this)");
}
}
In server side, I hooked DataGrid.ItemCreated event and add the event
handlers to AlternatingItems(DataGridItem corresponding to <tr>, TableCell
corresponding to <td>)
In Client javascript code, I change cursor with <tr>'s onmouseover event,
change <tr>'s bgColor in onclick event, exchange <td>'s bgColor between
second column(TableCell tc=dgi.Cells[1]).
Note: Client javascript is case-sensitive, so not to use obj.bgcolor.
=============================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.