3

Is it possible to select multiple rows in grid-view without using check-box?

My code is this

<asp:GridView ID="Grid_add_data" runat="server" AutoGenerateColumns="False" BackColor="White"
     ShowFooter="True" CssClass="mGrid" meta:resourcekey="Grid_add_dataResource1">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="chkRows" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="From Time" meta:resourcekey="TemplateFieldResource1">
            <ItemTemplate>
                <asp:Label ID="Lbl_from_time" runat="server" Text='<%# Bind("FromTime") %>' meta:resourcekey="Lbl_from_timeResource1"></asp:Label></ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="To Time" meta:resourcekey="TemplateFieldResource2">
            <ItemTemplate>
                <asp:Label ID="Lbl_to_time" runat="server" Text='<%# Bind("ToTime") %>' meta:resourcekey="Lbl_to_timeResource1"></asp:Label></ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Quantum(MW)" meta:resourcekey="TemplateFieldResource3">
            <ItemTemplate>
                <asp:Label ID="Lbl_quantum" runat="server" Text='<%# Bind("Quantum") %>' meta:resourcekey="Lbl_quantumResource1"></asp:Label></ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EditRowStyle CssClass="GridViewSelectedRowStyle" VerticalAlign="Top" />
    <FooterStyle CssClass="GridViewFooterStyle" />
    <HeaderStyle BackColor="#6699FF" CssClass="GridViewHeaderStyle" Font-Bold="True"
        ForeColor="White" VerticalAlign="Bottom" />
    <PagerStyle CssClass="GridViewPagerStyle" />
    <RowStyle CssClass="GridViewRowStyle" HorizontalAlign="Center" VerticalAlign="Top" />
    <SelectedRowStyle CssClass="GridViewSelectedRowStyle" VerticalAlign="Top" />
</asp:GridView>

3 Answers 3

2

We can take a hidden field inside a gridview and on click of girdview row, means on selected index event, find the hidden field in selected row we can make it as 1 . now with loop of each row we can find the rows having hidden field value as 1

thats the way i think we can achieve,

in case of select and de select we can toggle the value of hidden field

Sign up to request clarification or add additional context in comments.

Comments

0

You have to workaround with a variable/list(preferably client side), where click on each row inserts the id of the selected row in that variable (comma separated in case of multiple rows). If the id is already present, then delete that id from that variable (assuming that row is clicked twice and is no longer required for the selection).

Comments

0

This would be a two fold process. The first would be to issue the proper callback. You could do that with a $.ajax call if you wanted, but it looks like this:

javascript:__doPostBack(&#39;ctl00$MainContent$GridView1&#39;,&#39;Select$**n**&#39;)

The importance of that string is two fold, first the fully qualified name of the grid, and second the n. It's the index of the row (zero-based) that you want to select. After that you'll need to remove the class GridViewSelectedRowStyle from any currently selected rows and change the class of the <tr> to GridViewSelectedRowStyle. You could easily remove them by selecting them:

$('.GridViewSelectedRowStyle').removeClass('GridViewSelectedRowStyle');.

Adding them could prove a little trickier, but if you pass the reference to the <tr> when it's clicked on, it should be pretty straight forward.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.