gridview 代码:
<asp:GridView ID="gvCategories" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField Visible="true">
<ItemTemplate>
<div id="categoryID"><%# Eval("CategoryID") %></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Literal ID="litCategoryName" runat="server" Text='<%# Eval("CategoryName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<input type="button" value="Save" onclick="Save(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<div id="message" ></div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
javascript save函数
function Save(obj)
{
var row = null;
if(IsFireFox())
{
row = obj.parentNode.parentNode;
}
else
{
row = obj.parentElement.parentElement;
}
var message = row.getElementsByTagName("DIV");
row.style.backgroundColor = 'Yellow';
message[1].innerHTML = 'Saving!';
// Here you can also call the server side method to save the item to the database
window.setTimeout(function() { row.style.backgroundColor = 'White'; message[1].innerHTML = 'Saved!'; },2000);
}
ref: http://gridviewguy.com/ArticleDetails.aspx?articleID=241