protected void passSubContractorInfoToNewPage(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Sub_Contractor subC = (Sub_Contractor)e.Row.DataItem;
HyperLink LoadSubContractorDetails = (HyperLink)e.Row.FindControl("LoadSubContractorDetails");
LoadSubContractorDetails.NavigateUrl = ResolveUrl(@"~/SubContractDetails.aspx?id=" + subC.id.ToString());
}
}
<asp:GridView ID="GridView2" OnRowDataBound="passSubContractorInfoToNewPage" runat="server" AllowPaging="True" AllowSorting="True" CssClass="gridview" AutoGenerateColumns="false" DataSourceID="GridDataSource1">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="InvoiceInfoID" />
<asp:BoundField DataField="Company Name" HeaderText="Company Name" SortExpression="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="LoadSubContractorDetails" runat="server" Text="Show Details"/>
</ItemTemplate>
</asp:TemplateField>
</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>
这将返回 subContractor 为 NULL 的错误,错误为:
Unable to cast object of type 'System.Data.DataRowView' to type 'Sub_Contractor'.
也试过
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView view = (DataRowView)e.Row.DataItem;
但仍然没有喜悦......
为什么它不接分包商有人可以告诉我吗?
谢谢