Gridview и DbCommand - PullRequest
       20

Gridview и DbCommand

1 голос
/ 26 февраля 2010

Мне нужно заполнить сетку с помощью команды dbcoommand.

Код, который я написал:

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();   

команда возвращает строки правильно, но сетка не заполнена,Зачем ?Заголовок вида сетки:

<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" >

как мне это сделать?

спасибо

1 Ответ

0 голосов
/ 26 февраля 2010

забыл GridView1.Databind ();

...