1

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 != 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();
        }
    }


}

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

1 Answer 1

0

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.