I need to
<asp:TemplateField HeaderText ="ename">
<ItemTemplate > <asp:Label ID="lbl2" Tex开发者_开发问答t ='<%#Eval("ID") %>' runat ="server" >
</asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID ="textbox1" Text='<%#Eval("name")%>' runat ="server" ></asp:TextBox>
<asp:LinkButton ID ="link1" Text='<%#Eval("name")%>' runat ="server" ></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
i have an textbox and link button in Edit itemtemplate based on the condition()
if(Text ='<%#Eval("ID") %>')
id=1 show textbox[edit item temalpate]
id=2 show link button[edit item temalpate]
id=3 show link button[edit item temalpate]
now in link button i have value [Text='<%#Eval("name")%>']
(eg:www.stackoverflow.com ,google.com)
so that one an user clicks on the link button open a new browser window and show that website show to open an new browser window on the clcik of the link button
Could you use a HyperLink control rather than a LinkButton?
eg
<asp:HyperLink id="hyperlink1"
NavigateUrl="<%#Eval('name')%>"
Text="<%#Eval('name')%>"
Target="_blank"
runat="server"/>
You can just bind to the OnClientClick
event of the LinkButton
. I would do all of this by implementing the OnDataBinding
event for that control:
Eg:
// In your .aspx
<asp:LinkButton ID ="yourButton" runat="server" OnDataBinding="yourButton_DataBinding" />
//In your .cs
protected void yourButton_DataBinding(object sender, System.EventArgs e)
{
LinkButton btn = (LinkButton)(sender);
btn.Text = Eval("name");
btn.OnClientClick = string.Format("window.open('{0}', 'yourNewWindow'); return false;", Eval("name"));
}
If you need more info on how the javascript window.open works check out this link:
http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
<asp:HyperLink id="hyperlink1" NavigateUrl="<%#Eval('name')%>" Text="<%#Eval('name')%>" Target="_blank" runat="server" />
before NavigateUrl we need to the code "http" as shown then it woks fine
NavigateUrl='<%# "http://" + Eval('name')%>'
can Add
OnClientClick="aspnetForm.target ='_blank';"
so on click it will call Javascript function an will open respective link in News tab.
<asp:LinkButton id="lbnkVidTtile1" OnClientClick="aspnetForm.target ='_blank';" runat="Server" CssClass="bodytext" Text='<%# Eval("newvideotitle") %>' />
精彩评论