C# 为什么rowdatabound可以';在gridview中找不到链接按钮?
我试图通过RowDataBound从gridview获取链接按钮,但它返回null,为什么?名字是正确的。即使您可以在代码中看到,但它仍然不起作用 GridView:C# 为什么rowdatabound可以';在gridview中找不到链接按钮?,c#,asp.net,.net,gridview,webforms,C#,Asp.net,.net,Gridview,Webforms,我试图通过RowDataBound从gridview获取链接按钮,但它返回null,为什么?名字是正确的。即使您可以在代码中看到,但它仍然不起作用 GridView: <asp:GridView ID="grdViewWorks" OnRowDataBound="grdViewWorks_RowDataBound" runat="server" OnRowCommand="grdViewWorks_RowCommand" AutoGenerateColumns="false" E
<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>
lb总是空的。为什么? 在将任何内容放入rowdatabound事件之前,必须使用此条件
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lb = e.Row.FindControl("btnShowContractors") as LinkButton;
ScriptManager.GetCurrent(this).RegisterPostBackControl(lb);
}
这样试试
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lb = e.Row.FindControl("btnShowContractors") as LinkButton;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lb = e.Row.FindControl("btnShowContractors") as LinkButton;
}