【问题标题】:DetailsviewInside Linkbutton onclick it rediects and open newtab详细信息查看内部链接按钮 onclick 它重定向并打开新选项卡
【发布时间】:2011-07-20 05:05:56
【问题描述】:

我正在使用详细信息视图 Itemtemplete 中的详细信息视图我有链接按钮,当单击该链接按钮时,它需要重定向并打开新选项卡,我使用此代码

protected void lnkPost_Click(object sender, EventArgs e) {

    DetailsViewRow row= (DetailsViewRow)((LinkButton)sender).NamingContainer;
    int postID = Convert.ToInt32((row.FindControl("lblPostID") as Label).Text);
    if (postID != null)
    {
       string Query = "Select * from GigPost where GigPostID='" + postID + "'";
        SqlCommand cmd = new SqlCommand(Query, cn);
        SqlDataReader dr = cmd.ExecuteReader();

        if (dr.Read())
        {
            string Postsource = dr["PostSource"].ToString();
            Response.Write("<script> window.open('"+ Postsource+"' ); </script>");
            Response.End();
        }
    }


}

我收到“无法将'System.Web.UI.WebControls.DetailsView' 类型的对象转换为'System.Web.UI.WebControls.DetailsViewRow'。”这个错误请帮助我如何解决这个问题

问候, 文卡特

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    DetailsViewRow 行 = (DetailsViewRow)(((LinkBut​​ton)sender).NamingContainer);

    可能工作 - (未经测试)

    但实际上 - 使用 DetailsView 的 ItemCommand 并获取当前数据键有什么问题?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多