开发者

DetailsviewInside Linkbutton onclick it rediects and open newtab

I am working with Details view inside details view Itemtemplete i have link button when click that link button it need to redirect and open new tab for that i use this code

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 != nul开发者_高级运维l)
    {
       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();
        }
    }


}

I am getting "Unable to cast object of type 'System.Web.UI.WebControls.DetailsView' to type 'System.Web.UI.WebControls.DetailsViewRow'." this error please help me how to resolve this issue

Regards, Venkat


DetailsViewRow row = (DetailsViewRow)(((LinkButton)sender).NamingContainer);

may work - (untested)

But really - what's wrong with using the ItemCommand of the DetailsView and grab the current datakey?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜