我是.net开发者。我只是想知道如何使网格视图行可点击,如果用户点击行,然后网格视图LinkButton点击它的id点击。
编码可能吗?
这是我的网格视图设计:
<asp:GridView ID="GV_ViewReminder" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
GridLines="None" Width="100%" onrowcommand="GV_ViewReminder_RowCommand"
DataKeyNames="Id" ondatabound="GV_ViewReminder_DataBound"
onpageindexchanging="GV_ViewReminder_PageIndexChanging"
onprerender="GV_ViewReminder_PreRender"
onrowdatabound="GV_ViewReminder_RowDataBound"
onsorting="GV_ViewReminder_Sorting">
<RowStyle CssClass="grid1" HorizontalAlign="Left" />
<Columns>
<asp:TemplateField>
<HeaderStyle CssClass="headinglist_bg" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Reminder Text" SortExpression="Reminder_Text">
<HeaderStyle CssClass="headinglist_bg" />
<ItemTemplate>
<asp:LinkButton ID="lbut_reminder" runat="server"
CommandArgument='<%# Eval("Id") %>' CommandName="View"
Text='<%# Eval("Reminder_Text").ToString().Length > 15 ? Eval("Reminder_Text").ToString().Substring(0,15)+"..." :Eval("Reminder_Text") %>'
Tooltip='<%# Bind("Reminder_Text") %>'></asp:LinkButton>
</ItemTemplate>
<HeaderTemplate>
<asp:LinkButton ID="lbut_sorttext" runat="server"
CommandArgument="Reminder_Text" CommandName="Sort" CssClass="normaltext"
Font-Bold="true" Text="Reminder Text"></asp:LinkButton>
<asp:PlaceHolder ID="placeholdertext" runat="server"></asp:PlaceHolder>
</HeaderTemplate>
<ItemStyle CssClass="quicklink" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Reminder Date" SortExpression="Reminder_Date">
<HeaderTemplate>
<asp:LinkButton ID="lbut_sortdate" runat="server"
CommandArgument="Reminder_Date" CommandName="Sort" CssClass="normaltext"
Font-Bold="true" Text="Reminder Date"></asp:LinkButton>
<asp:PlaceHolder ID="placeholderdate" runat="server"></asp:PlaceHolder>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Reminder_Date") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="headinglist_bg" />
</asp:TemplateField>
</Columns>
<EmptyDataRowStyle BorderWidth="0px" Width="0px" />
<EmptyDataTemplate>
<asp:Label ID="Label2" runat="server" ForeColor="Red"
Text="No Records are found"></asp:Label>
</EmptyDataTemplate>
<PagerStyle CssClass="pager" HorizontalAlign="Center" VerticalAlign="Middle" />
<PagerTemplate>
<table>
<tr>
<td>
<asp:ImageButton ID="ImageButton1" runat="server"
AlternateText="Go to First Page" CommandArgument="First" CommandName="Page"
ImageUrl="../images/1330128819_resultset_first.png" />
</td>
<td>
<asp:ImageButton ID="ImageButton2" runat="server" AlternateText="Previous Page"
CommandArgument="Prev" CommandName="Page"
ImageUrl="../images/1330128981_resultset_previous.png" />
</td>
<td>
Page <asp:DropDownList ID="ddlPages" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddlPages_SelectedIndexChanged">
</asp:DropDownList>
of
<asp:Label ID="lblPageCount" runat="server"></asp:Label>
</td>
<td>
<asp:ImageButton ID="ImageButton3" runat="server" AlternateText="Next Page"
CommandArgument="Next" CommandName="Page"
ImageUrl="../images/Farm-Fresh_resultset_next.png" />
</td>
<td>
<asp:ImageButton ID="ImageButton4" runat="server"
AlternateText="Go to Last Page" CommandArgument="Last" CommandName="Page"
ImageUrl="../images/1330128876_resultset_last.png" />
</td>
</tr>
</table>
</PagerTemplate>
<FooterStyle CssClass="pager" VerticalAlign="Bottom" />
<HeaderStyle HorizontalAlign="Left" />
</asp:GridView>
我只想让ID为“lbut_reminder”的LinkButton在用户点击整行网格视图时被触发。
答案 0 :(得分:1)
只需添加此脚本:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$(".css-class").click(function () {
window.location = $(this).find("a").attr("href");
return false;
})
});
</script>