Pergunta

i 'm .net developer. i just want to know how to make grid view row clickable and if user clicks row then Grid View LinkButton with it's id click fired.

Is that possible with coding ??.

here is my grid view design:

<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&nbsp;<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>

i just want my LinkButton with id "lbut_reminder" get fired while user clicks entire row of grid view.

Foi útil?

Solução

just add this script:

<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        $(".css-class").click(function () {
            window.location = $(this).find("a").attr("href");
            return false;
        })
    });
</script>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top