views:

17

answers:

1

Hai Pupils,

     I am a beginner in Dot net Domain.Presently Im creating a web portal for one of our client.In my portal i have displayed the News headline and a button for details in a Grid view. when i click on the button it has to show the detailed news from DB in another grid view. I have done a code on it.,but it shows some error.I have displayed the code below.Please help me to overcome this problem.

My Code IS

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer && e.Row.RowType != DataControlRowType.Pager) { Button btn = (Button)e.Row.FindControl("Button12"); btn.CommandArgument = e.Row.RowIndex.ToString(); } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "newsbtn") { int index = int.Parse(e.CommandArgument.ToString()); string key = GridView2.DataKeys[index].Value.ToString();

        SqlDataAdapter da = new SqlDataAdapter("select **img,news,detail** from News where news=@n", connect.con());
        da.SelectCommand.Parameters.AddWithValue("@n", key);
        da.Fill(ds, "more");

        //if (!IsPostBack)
        //{
            GridView1.DataSource = ds;
            GridView1.DataBind();
        //}
    }
}

The error it shows is:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'detail'.

A: 

may be these will help
1. Master/Detail Using a Selectable Master GridView with a Details DetailView use Gridview instead of DetailsView to show child records
2. Or you can try little more advanced approach GridView control to show master-child or master-slave data, written in c#, asp.net, and javascript

Cheers

Sandy
thank u sir.,it was useful. Will u please explain the error occured in my code.,The Error is: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'detail'.