locked
Display DetailsView 2nd Page Record on a Label RRS feed

  • Question

  • User-1520784531 posted

    Hey there,

    I'm using GridView to select and DetailsView to Display. When i click on the GridView, it supposed to display 2 records on the DetailsView by Enabling Paging. However my problem is to display the value of the Details View on a label, it only able to read the First record(meaning the 1st page) on my Details View and display it on the label, but not my Second record on my Details View. How do I display the 2nd record on the Details View to a Label? Here's my code for the GridView Selected Index Change.

     protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    string strConnectionString = ConfigurationManager.ConnectionStrings["EEEConnectionString"].ConnectionString;

    SqlConnection myConnect = new SqlConnection(strConnectionString);


    string strCommandText = "SELECT [Order].OrderNo, [Order].OrderStatus, [Order Details].OrderQty, Product.Qty FROM [Order] INNER JOIN [Order Details] ON [Order].OrderNo = [Order Details].OrderNo INNER JOIN Product ON [Order Details].ProdID = Product.ProdID WHERE ([Order].OrderNo = @OrderNo)";

    myConnect.Open();

    GridViewRow rw = GridView1.SelectedRow;
    Label2.Text = rw.Cells[0].Text;


    foreach (GridViewRow row in GridView1.Rows)
    {

    SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
    cmd.Parameters.AddWithValue("@ID", Label2.Text );
    SqlDataReader reader = cmd.ExecuteReader();
    if (reader.Read())
    {
    Label3.Text = reader["OrderQty"].ToString();
    Label4.Text = reader["Qty"].ToString();
    }

    }

    myConnect.Close();

    }

     Thanks!

    Monday, July 4, 2011 7:16 AM

Answers

  • User3866881 posted

    Hello fab69:)

    This is because when you select a record from the GridView, GridView_SelectIndexChanged is fired and everything goes normally. However, when you switch to the 2nd one, SelectIndexChanged  won't get fired and no effect...

    My suggestion——Try to call like this:

    protected void DetailsView_PageIndexChanged(……)
    {

         GridView1_SelectedIndexChanged(null,null);

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 5, 2011 10:11 PM

All replies

  • User3866881 posted

    Hello fab69:)

    This is because when you select a record from the GridView, GridView_SelectIndexChanged is fired and everything goes normally. However, when you switch to the 2nd one, SelectIndexChanged  won't get fired and no effect...

    My suggestion——Try to call like this:

    protected void DetailsView_PageIndexChanged(……)
    {

         GridView1_SelectedIndexChanged(null,null);

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 5, 2011 10:11 PM
  • User-614386673 posted

    I think it will be better if you go for DetailsView rather than writing this much code.

    You can put a new detail view with OrderQty and Qty. add the parameter from the gridviewselectedindex changed event.

    Wednesday, July 6, 2011 3:18 AM