我必须使用dbcoommand填充gridview。
我写的代码是:
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" >
我该怎么办?
感谢
答案 0 :(得分:0)
忘了GridView1.Databind();