最佳解答者
ASP.Net Grid View Question

問題
-
Hi
I have a page which has a Grid view to display some records and allow them to make changes on it. On the grid view I has several Textboxs and Label and a check box.
The changes can be make via a Edit/Save Button (asp:button) and programm it to only update when the check box for the record has been checked.
I am wondering if there any way that I could highlight a grid view row after they modified a record (a textbox's value)
I tried to use the textbox.changes(), it does not seems to work.
Thanks in advances.2008年7月14日 下午 03:45
解答
-
Hi Chi,
I did a quick test and highlight a GridViewRow whenever the TextBox got focus (or being updated in your case).
FYI: http://www.flickr.com/photos/coltkwong/2672607949/
It is done by javascript and the code is:
Code Snippet<script type="text/javascript">
function ChangeColor()
{
var obj = window.event.srcElement;if(obj.tagName == 'INPUT' && obj.type == 'text')
{
obj = obj.parentElement.parentElement;
obj.style.background = 'orange';
}
}
</script><asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtColor" runat="Server" onfocus="java-script:ChangeColor();"/>
</ItemTemplate>
</asp:TemplateField>Of course, you can add some NULL checking in the code, and revert the background color to normal if users undo his changes in GridView.
Regards,
Colt
2008年7月16日 上午 03:45
所有回覆
-
Hi Colt,
Thanks for your information. I am sorry that I did not explain it properly.
What I am trying to do is to highlight the row after the textbox which is on the grid view get changes. Because I would like to let the use know which rows they have modified, so that they can decide whether they want to check the checkbox.
Sorry to make you confused.2008年7月15日 上午 07:23 -
Hi Chi,
I did a quick test and highlight a GridViewRow whenever the TextBox got focus (or being updated in your case).
FYI: http://www.flickr.com/photos/coltkwong/2672607949/
It is done by javascript and the code is:
Code Snippet<script type="text/javascript">
function ChangeColor()
{
var obj = window.event.srcElement;if(obj.tagName == 'INPUT' && obj.type == 'text')
{
obj = obj.parentElement.parentElement;
obj.style.background = 'orange';
}
}
</script><asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtColor" runat="Server" onfocus="java-script:ChangeColor();"/>
</ItemTemplate>
</asp:TemplateField>Of course, you can add some NULL checking in the code, and revert the background color to normal if users undo his changes in GridView.
Regards,
Colt
2008年7月16日 上午 03:45 -
Hi Colt
Thanks very much for your help, you are amazing. It works very well. I did not use Edit Template for it, I do not know why I have a bade habit that I love to type the code and program it rather than using Object data source ... etc.
I have one more question, about the Javascript.
Do you recommend me to register it on Page Load event? or just place it on aspx page?
Thanks a lots2008年7月16日 上午 07:51