我需要完整的单元格可点击。我尝试了一些解决方案,但它们无法使单元格可点击,文本只能点击。
protected void gvSearchResult_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
e.Row.Cells[0].Attributes["style"] = "cursor:pointer";
e.Row.Cells[0].Text = "<a href='/Pages/ProjectEdit.aspx?ID="+ ((Label)e.Row.FindControl("lblID")).Text+"'>" + ((Label)e.Row.FindControl("lblID")).Text + "</a>";
}
}
..............................
<Columns>
<asp:TemplateField ItemStyle-CssClass="ItemClass" ItemStyle-Width="8%" HeaderText="Project ID">
<ItemTemplate>
<asp:Label style="cursor:pointer;" ID="lblID" runat="server" Text='<%# Eval("id")%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
答案 0 :(得分:2)
您可以按照与样式相同的方式为单元格指定onclick
属性。
e.Row.Cells[0].Attributes["onclick"] = "location.href='/Pages/ProjectEdit.aspx?ID='";
或者将链接包裹在div
的全宽和高度(更适合SEO)
e.Row.Cells[0].Text = "<a href=\"/Pages/ProjectEdit.aspx?ID=\"><div style=\"width: 100%; height: 100%;\">CLickMe</div></a>";