开发者

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"))) %>'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜