我的asp頁面上有一個GridView。我想用按鈕單擊來更改LinqDataSource。這是因爲我有2個數據庫視圖,您必須能夠根據需要查看其中的一個視圖。當我嘗試將GridView綁定到我的任何LinqDataSource時,我的問題不會發生。用按鈕改變LinqDataSource點擊
我的C#代碼:
protected void Page_Load(object sender, EventArgs e)
{
this.Grid.DataSource = lqds_Grid1;
this.Grid.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.Grid.DataSource == lqds_Grid1)
{
this.Grid.DataSource = lqds_Grid2;
this.Grid.DataBind();
}
else
{
this.Grid.DataSource = lqds_Grid1;
this.Grid.DataBind();
}
}
我的ASP代碼:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="AddressReporting._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:LinqDataSource ID="lqds_Grid1" runat="server"
ContextTypeName="AddressReporting.MobileGateway" EntityTypeName=""
OrderBy="AdrID, Country" TableName="BarcodeWithLocation">
</asp:LinqDataSource>
<asp:LinqDataSource ID="lqds_Grid2" runat="server"
ContextTypeName="AddressReporting.MobileGateway" EntityTypeName=""
OrderBy="AdrID, Country" TableName="BarcodeWithLocationSorted">
</asp:LinqDataSource>
<asp:GridView ID="Grid" runat="server" AllowPaging="True"
AutoGenerateColumns="False" Height="217px" Width="268px">
</asp:GridView>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</asp:Content>
哪裏是格列? –
它們從數據庫中檢索 – Lahib
它們不像您設置的那樣'AutoGenerateColumns =「False」' –