views:

18

answers:

1

Hi,i have to fill a gridview with a dbcoommand.

The code that i have wrote is:

EntityConnection entityConnection = (EntityConnection)db.Connection;
        DbConnection storeConnection = entityConnection.StoreConnection;
        storeConnection.Open();
DbCommand command = storeConnection.CreateCommand();
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("StatoID", DropDownListStato.SelectedValue));
    command.Parameters.Add(new SqlParameter("InizioPeriodo", DateTime.Parse(TxtIntervalloDataInizio.Text + " 00:00")));
    command.Parameters.Add(new SqlParameter("FinePeriodo", DateTime.Parse(TxtIntervalloDataFine.Text + " 23:59")));
    command.Parameters.Add(new SqlParameter("AccountID", ddlDipendenti.SelectedValue));
    command.Parameters.Add(new SqlParameter("Prenotazioni", ChkPrenotazioni.Checked.ToString()));
    command.Parameters.Add(new SqlParameter("PrenotazioniEffettuate", DropDownListPrenotazioniEffettuate.SelectedValue == "True" ? 1 : 0));
    command.Parameters.Add(new SqlParameter("UscitaServizio", DropDownListUscitePerServizio.SelectedValue == "True" ? 1 : 0));

    command.CommandText = "up_missioni_get_data";        
    GridView1.DataSource = command.ExecuteReader();   

the command return correctly the rows but the grid view isn't filled. Why ? The header of grid view is:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnRowDataBound="GridView1_RowDataBound"
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="MissioneID"  
            PageSize="20" Width="100%" CellPadding="4" CellSpacing="1"
              GridLines="None" >

how can i do?

thanks

A: 

forgot GridView1.Databind();

FiveTools