2013-02-21 54 views
0

因此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(); 

我該怎麼做? 請指教? 感謝

+0

認爲你需要一個WHERE子句在你的SQL查詢? – codingbiz 2013-02-21 12:07:35

回答

1

如果您LoadSubContractors()函數的返回類型是像一個List或者你可以簡單地在代碼中設置數據源的後面,然後手動將數據綁定DataSet

myGridView.DataSource = LoadSubContractors(); 
myGridView.DataBind() 
+0

謝謝肖恩男士 – John 2013-02-21 12:33:32

+0

完全沒問題=] – Sean 2013-02-21 12:39:54