我有以下aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BorderStyle="None" Font-Names="Verdana" Font-Size="12px"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" ShowHeader="False"
GridLines="None" EnableModelValidation="True" Width="22%" >
<RowStyle BorderStyle="None" Height="40px" HorizontalAlign="Left"/>
<Columns>
<asp:HyperLinkField Text="<img src='../Images/CMM/download.png'/>"></asp:HyperLinkField>
<asp:ButtonField CommandName="Select" DataTextField="codigo" DataTextFormatString="{0:d}"
ItemStyle-HorizontalAlign="Left" ControlStyle-Font-Underline="true">
<ControlStyle Font-Underline="True" />
</asp:ButtonField>
</Columns>
<EditRowStyle BorderStyle="None" />
<AlternatingRowStyle BorderStyle="None" />
</asp:GridView>
我有以下 apsx.cs 文件代码:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
CallSaveAs(GridView1.SelectedRow.Cells[1].Text);
}
GridView1.SelectedRow.Cells[1].Text 是空的,但我可以在 Debug 上看到它
我也试过:
ButtonField bf = (ButtonField)GridView1.SelectedRow.Cells[1].Controls[0];
但我无法将类型“System.Web.UI.Control”转换为“System.Web.UI.WebControls.ButtonField”
终于找到了解决办法:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs)
{
LinkButton lb = (LinkButton)GridView1.SelectedRow.Cells[1].Controls[0];
CallSaveAs(lb.Text);
}