String.Format with 2 parameters (ID Database and ClientID)
I would like that result, was
<a id="ctl00" onclick="OpenModal(704520,'asdf')">
<img id="crico" src="../online/img_admin/icon_hist.gif" />
</a>
How to do?
I'm trying so:
<asp:HyperLink ID="HyperLink4" runat="server"
onclick='<%# String.Format("OpenModal({0},{1})", DataBinder.Eval(Container.DataItem, "intid"), (Image)GridView1.FindControl("img_Historico").ClientID) ) %>' >
<asp:Image ID="img_Historico" runat="server" />
</asp:HyperLink>
so basically is:
OpenModal(Id_do_DataBase, 'ClientID of image')
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0030: Cannot convert type 'string' to 'System.Web.UI.WebControls.Image'
Not working my code, so I asked here.
I also tried: onclick='<%# String.Format("AbreModal({0},{1})", DataBinder.Eval(Container.DataItem, "intid"), img_Historico.ClientID )
nothing works! :(
You want
((Image)GridView1.FindControl("img_Historico")).ClientID
Also, if your data binding expression is so complex, then you should refactor it into a property or method:
protected string ImgHistoricoClientID
{
get {return ((Image)GridView1.FindControl("img_Historico")).ClientID;}
}
Databinding expression:
onclick='<%# String.Format("OpenModal({0},{1})", DataBinder.Eval(Container.DataItem, "intid"), ImgHistoricoClientID) ) %>' >
In fact, I would use the ItemDataBound
event of the GridView to set the whole thing.
The problem lies in this line:
(Image)GridView1.FindControl("img_Historico").ClientID
ClientID is a string and you are casting it to an image. It should be:
GridView1.FindControl("img_Historico").ClientID
To make it clearer this would also work (with an unnessisary cast)
((Image)GridView1.FindControl("img_Historico")).ClientID
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.