因此ATM我的代碼工作正常。我使用SqlDataSource鏈接到網格數據源並顯示一個表。它顯示錶格中的一列,並用作超鏈接來導航到不同的頁面。將方法鏈接到數據源
<asp:BoundField DataField="Company Name" HeaderText="Company Name" SortExpression="false" />
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="LoadSubContractorDetails" runat="server" Text="Show Details"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
There are currently no items in this table.
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="GridDataSource1" runat="server"
ConnectionString="<%$ConnectionStrings:ClarkesTest4FromMaster1ConnectionString %>"
SelectCommand="SELECT id, [Company Name] FROM [Sub Contractor] ORDER BY [Company Name]" >
</asp:SqlDataSource>
protected void passSubContractorInfoToNewPage(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView view = (DataRowView)e.Row.DataItem;
HyperLink LoadSubContractorDetails = (HyperLink)e.Row.FindControl("LoadSubContractorDetails");
LoadSubContractorDetails.NavigateUrl = ResolveUrl(@"~/SubContractDetails.aspx?id=" + view["id"].ToString() + "&InvoiceId=" + this.CurrentInvoiceId.ToString());
}
}
但是正如我所說的代碼工作正常,但它顯示在數據庫表中的所有記錄,我只想要顯示我有這從另一個函數返回的subcontractos:
LoadSubContractors();
我該怎麼做? 請指教? 感謝
認爲你需要一個WHERE子句在你的SQL查詢? – codingbiz 2013-02-21 12:07:35