How to access a data key?
I have a GridView
with textboxes in its cells. A JavaScript function is called on changing textbox's contents. I want to pass to the function a data key of the row t开发者_如何学JAVAo which the textbox belongs, but don't know how I can do that.
The following gives me an error message:
<asp:TextBox ID="txtWFShipDate" runat="server"
Text='<%#Eval("StrShipDate") %>' BorderStyle="None" Width="80%"
CssClass="date"
onchange="JSSaveWorkflowChanges(this, '<%# Eval("BookStemCommon") %>');">
</asp:TextBox>
BookStemCommon
is the data key name.
Try like this:
onchange='<%# string.Format("JSSaveWorkflowChanges(this, \"{0}\");", Eval("BookStemCommon")) %>'
or a better and safer way using JavaScriptSerializer to properly encode the value that will be passed to the javascript function:
onchange='<%# string.Format("JSSaveWorkflowChanges(this, {0});", new JavaScriptSerializer().Serialize(Eval("BookStemCommon"))) %>'
精彩评论