Gridview 和 DbCommand
我必须用 dbcommand 填充 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" >
我该怎么办?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
忘记了 GridView1.Databind();
forgot GridView1.Databind();