所以 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());
}
}
但是,正如我所说,代码工作正常,但它显示了数据库表中的所有记录,我只想显示从我拥有的另一个函数返回的分包商:
LoadSubContractors();
我该怎么做呢?请指教?谢谢