0

我正在设计一个基于网络的物流系统。在我的视图订单页面中,我有一些绑定到数据源的下拉列表和旁边的网格视图。当操作员选择相关的下拉列表时,我想更改网格视图数据源。我写了代码,但它不工作,网格视图不显示任何数据。请告诉我我做错了什么。

//Code for firing drop down list event 

        public void ddlVehicleFire(Object sender, EventArgs e)
        {
        GridView1.DataSource = VehicleDastaSource;
        GridView1.DataBind();
        }

//aspx页面

<asp:SqlDataSource ID="VehicleDastaSource" runat="server" ConnectionString="<%$ ConnectionStrings:LGDB %>" SelectCommand="SELECT [vehicleID], [manufacturer], [VIN], [capacity], [weight_], [dateOfProduction] FROM [vehicle]"></asp:SqlDataSource>

 Drop down list
   asp:DropDownList ID="DDLVehicle" runat="server" DataSourceID="vehicle"     DataTextField="vehicleID" DataValueField="vehicleID" AutoPostBack="True" OnSelectedIndexChanged="ddlVehicleFire"></asp:DropDownList>

通过选择车辆 ID,我想在网格视图中显示相关数据

4

1 回答 1

0

1.make autopostback true 为下拉

C#

if (IsPostBack)

  {
   //your code here; 
  }

VB.net

If IsPostBack Then
        'your code here;

End If

.aspx

<Columns>
        <asp:BoundField HeaderText="Id" 
            DataField="Id" ReadOnly="true" />
        <asp:BoundField DataField="CreatedBy" 
            ReadOnly="true" HeaderText="Created By" />
        <asp:BoundField DataField="CreateTime" 
            ReadOnly="true" HeaderText="Date Created"
            DataFormatString="{0:d}" />
    </Columns>
于 2013-09-12T04:41:14.497 回答