0
我想通過RowDataBound從gridview中獲取鏈接按鈕,但它返回null,爲什麼?名字是正確的。即使你可以在代碼中看到,但它仍然不起作用。爲什麼rowdatabound在gridview中找不到鏈接按鈕?
GridView控件:
<asp:GridView ID="grdViewWorks" OnRowDataBound="grdViewWorks_RowDataBound" runat="server" OnRowCommand="grdViewWorks_RowCommand" AutoGenerateColumns="false" EmptyDataText="No Data Found"
CssClass="table table-responsive table-bordered table-striped">
<Columns>
<asp:TemplateField HeaderText="Work No">
<ItemTemplate>
<asp:Label ID="lblWorkNo" runat="server" Text='<%# Eval("WorkNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NIT No">
<ItemTemplate>
<asp:Label ID="lblNITNo" runat="server" Text='<%# Eval("NIT_No") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="WorkName" HeaderText="Work Name" />
<asp:BoundField DataField="OpeningDate" HeaderText="Opening Date" />
<asp:BoundField DataField="OpeningTime" HeaderText="Opening Time" />
<asp:BoundField DataField="OrganizationName" HeaderText="Organization" />
<asp:BoundField DataField="OfficeName" HeaderText="Office" />
<asp:TemplateField HeaderText="Show Contractors">
<ItemTemplate>
<asp:LinkButton ID="btnShowContractors" runat="server" Text="Show Contractors"
OnClick="btnShowContractors_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
的.cs
protected void grdViewWorks_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
LinkButton lb = e.Row.FindControl("btnShowContractors") as LinkButton;
ScriptManager.GetCurrent(this).RegisterPostBackControl(lb);
}
catch (Exception ex)
{
Utility.Msg_Error(this.Master, ex.Message);
}
}
磅總是空。爲什麼?