C#GridView绑定到下拉列表 [英] C# GridView bind to Dropdown list

查看:67
本文介绍了C#GridView绑定到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个完全像下面的页面,但是只有我需要从两个表中选择数据以显示在GridView中.谢谢!


i want exactly a page like below , but only i need to select data from two tables to display in the GridView. thx!


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <body>
    <form runat="server">
      <p><asp:dropdownlist

          id="DropDownList1"

          runat="server"

          autopostback="True">
          <asp:listitem selected>Sales Representative</asp:listitem>
          <asp:listitem>Sales Manager</asp:listitem>
          <asp:listitem>Vice President, Sales</asp:listitem>
      </asp:dropdownlist></p>
      <asp:sqldatasource

          id="SqlDataSource1"

          runat="server"

          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"

          selectcommand="SELECT LastName FROM Employees WHERE Title = @Title">
          <selectparameters>
              <asp:controlparameter name="Title" controlid="DropDownList1" propertyname="SelectedValue"/>
          </selectparameters>
      </asp:sqldatasource>
      <p><asp:listbox

          id="ListBox1"

          runat="server"

          datasourceid="SqlDataSource1"

          datatextfield="LastName">
      </asp:listbox></p>
    </form>
  </body>
</html>

推荐答案

ConnectionStrings:MyNorthwind %> " span> =" 从雇员那里选择姓氏标题= @Title" > < selectparameters > < asp:controlparameter 名称 =" controlid DropDownList1 " 属性名称 SelectedValue" > < /selectparameters > < /asp:sqldatasource > < p > < asp:listbox =" ListBox1" span> =" 服务器" span> =" SqlDataSource1" span> =" 姓氏" > < /asp:listbox > < /p > < /form > < /body > < /html >
ConnectionStrings:MyNorthwind%>" selectcommand="SELECT LastName FROM Employees WHERE Title = @Title"> <selectparameters> <asp:controlparameter name="Title" controlid="DropDownList1" propertyname="SelectedValue"/> </selectparameters> </asp:sqldatasource> <p><asp:listbox id="ListBox1" runat="server" datasourceid="SqlDataSource1" datatextfield="LastName"> </asp:listbox></p> </form> </body> </html>


(我知道他想知道的.)您将需要在数据库级别创建一个视图"或将两个表联接到存储过程中并从中返回一个数据集.现在从该数据集绑定gridview.此外,如果您不使用存储过程,则可以编写一个具有join的语句,这里也是从两个表中获取数据.您可以在Google上搜索联接的信息和语法.
(I got it what he wants to know.) You will need to create a "view" at database level or join the two tables in stored procedure and return a dataset from that. Now bind the gridview from that dataset. you will get the desired result.Also, if u r not using stored procedure then you may write a statement having join, here also, to fetch data from two table. You may google for information and syntax of joins.


这篇关于C#GridView绑定到下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆