C# 用于执行查询并在gridview中显示的下拉列表
我有以下情况,我有一个由数据库表填充的下拉列表,该表有以下列“id”、“name”和“query”,查询列记录是sql查询“select yada yada yada”,显示的列是“name” 此下拉列表位于包含表单标记的aspcontent中,代码如下图所示: 然后我有了我想要填充的gridview,它位于另一个asp内容部分C# 用于执行查询并在gridview中显示的下拉列表,c#,asp.net,gridview,drop-down-menu,C#,Asp.net,Gridview,Drop Down Menu,我有以下情况,我有一个由数据库表填充的下拉列表,该表有以下列“id”、“name”和“query”,查询列记录是sql查询“select yada yada yada”,显示的列是“name” 此下拉列表位于包含表单标记的aspcontent中,代码如下图所示: 然后我有了我想要填充的gridview,它位于另一个asp内容部分 <asp:Content ID="rightcontentdown" ContentPlaceHolderID="rightcontentdown" Runa
<asp:Content ID="rightcontentdown" ContentPlaceHolderID="rightcontentdown" Runat="Server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"></asp:GridView></asp:Content>
在您的SelectIndexChanged
事件中类似的内容如何。假设您的dropdownlist在文本字段中填充了“nome”,并且这些名称是唯一的,这将获取存储在数据库中的查询,然后您可以将其传递给另一个方法来执行查找并填充gridview。如果我不完全理解你的意图,请告诉我
SqlConnection Connection = null;
SqlCommand Command = null;
string ConnectionString = ConfigurationManager.ConnectionStrings["DB_testeConnectionString"].ConnectionString;
string CommandText = "SELECT rotina "
+ "FROM rotinas_comercial "
+ "WHERE nome = @someValue";
Connection = new SqlConnection(ConnectionString);
Connection.Open();
Command = new SqlCommand(CommandText, Connection);
Command.Parameters.Add(new SqlParameter("@someValue", DropDownList1.SelectedItem.Text));
var results = Command.ExecuteScalar();
Command.Dispose();
Connection.Close();
是的,这是可能的。您需要有一个后端函数从数据库加载查询,然后用查询创建一个命令,然后将其加载到gridview中。稍微搜索一下如何使用后端加载DB查询,您将很容易做到。您能提供一个链接和/或一些代码示例吗?“因为搜索“后端数据库查询”让我现在知道了下拉列表的SelectIndexChanged事件在哪里呢?我知道我需要为下拉列表放置一些代码来读取记录中的查询,但是我应该在那里放置什么?