简体   繁体   中英

Gridview and DbCommand

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

忘记了GridView1.Databind();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM