我需要完整的单元格可点击。我尝试了一些解决方案,但他们无法使单元格可点击,文本只能点击。
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>
您可以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>";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句