I have a gridview with the Template and it contains a LinkButton. When I click the button I want to open a link in new tab
我有一个使用模板的gridview,它包含一个LinkButton。当我单击按钮时,我想在新选项卡中打开一个链接
<Templates>
<Obout:GridTemplate runat="server" ID="tempCurrTask">
<Template>
<asp:LinkButton Text='<%# Container.DataItem["CurrentTask"] %>' ID="lnkbtnview2"
runat="server" Font-Underline="true" OnCommand="SELREC" CommandArgument='<%# Container.PageRecordIndex %>'></asp:LinkButton>
</Template>
</Obout:GridTemplate>
And the SELREC function is
SELREC功能是
protected void SELREC(object sender, CommandEventArgs e)
{
int rowIndex = int.Parse(e.CommandArgument.ToString());
Hashtable dataItem = grvLeads.Rows[rowIndex].ToHashtable() as Hashtable;
string id = Convert.ToString(dataItem["iTask_id"]); //.Split('|');
string rowIndexid = id.ToString();
//+ "/" + e.CommandName.ToString();
//ScriptManager.RegisterStartupScript(this, typeof(string), "openWindow", "window.open('Task.aspx?TaskID=" + rowIndexid.Trim() + "', '_newtab','left = 10, top=10,scrollbars=Yes,resizable=yes,width=1100,height=580'); ", true);
Response.Redirect("Task.aspx?TaskID=" + rowIndexid.Trim());
}
This link opens in the same tab. I want it to open in new tab, So I changed the asp:LinkButton to asp:HyperLink tag but the SELREC function is not called properly. I want to do it using LinkButton and I don't know how to do it by using the link button. So please anybody help me with sample code.
此链接将在同一选项卡中打开。我希望它在新标签中打开,所以我将asp:LinkButton更改为asp:HyperLink标签,但SELREC功能未正确调用。我想使用LinkButton这样做,我不知道如何使用链接按钮。所以请任何人帮我提供示例代码。
1 个解决方案
#1
0
Try this approach;
尝试这种方法;
<asp:LinkButton runat="server" href='<%# "Task.aspx?TaskID=" + MethodtoGenerateTaskId(parameter) %>' target="_blank">LinkButton</asp:LinkButton>
You should define MethodtoGenerateTaskId(parameter) in c# codebehind. Take CommandArgument as a parameter to this method.
您应该在c#codebehind中定义MethodtoGenerateTaskId(参数)。将CommandArgument作为此方法的参数。
protected string MethodtoGenerateTaskId(string command_arg)
{
int rowIndex = int.Parse(command_arg.ToString());
Hashtable dataItem = grvLeads.Rows[rowIndex].ToHashtable() as Hashtable;
string id = Convert.ToString(dataItem["iTask_id"]); //.Split('|');
string rowIndexid = id.ToString();
return rowIndexid.Trim();
}
and in markup;
和标记;
<asp:LinkButton runat="server" href='<%# "Task.aspx?TaskID=" + MethodtoGenerateTaskId(Container.PageRecordIndex.ToString()) %>' target="_blank">LinkButton</asp:LinkButton>
and if it works; pls mark it as answer...
如果它有效;请将其标记为答案......
#1
0
Try this approach;
尝试这种方法;
<asp:LinkButton runat="server" href='<%# "Task.aspx?TaskID=" + MethodtoGenerateTaskId(parameter) %>' target="_blank">LinkButton</asp:LinkButton>
You should define MethodtoGenerateTaskId(parameter) in c# codebehind. Take CommandArgument as a parameter to this method.
您应该在c#codebehind中定义MethodtoGenerateTaskId(参数)。将CommandArgument作为此方法的参数。
protected string MethodtoGenerateTaskId(string command_arg)
{
int rowIndex = int.Parse(command_arg.ToString());
Hashtable dataItem = grvLeads.Rows[rowIndex].ToHashtable() as Hashtable;
string id = Convert.ToString(dataItem["iTask_id"]); //.Split('|');
string rowIndexid = id.ToString();
return rowIndexid.Trim();
}
and in markup;
和标记;
<asp:LinkButton runat="server" href='<%# "Task.aspx?TaskID=" + MethodtoGenerateTaskId(Container.PageRecordIndex.ToString()) %>' target="_blank">LinkButton</asp:LinkButton>
and if it works; pls mark it as answer...
如果它有效;请将其标记为答案......