开发者

ASP.NET: Checkbox column inside a gridview: How to select one checkbox at Page_Load

开发者 https://www.devze.com 2023-04-04 06:50 出处:网络
I have a gridview with a check-box column.Evidently, each row will then have its own checkbox field. what am trying to achieve is to have only the topmost checkbox selected, preferably using javascrip

I have a gridview with a check-box column.Evidently, each row will then have its own checkbox field. what am trying to achieve is to have only the topmost checkbox selected, preferably using javascript. Ive searched for this but everybody seems to rely on a button click to select all/ deselect all.

Am manipulating the datasource attached to the grid, so i need it to display the checkbox on the first row selected.

Ideas?

<asp:GridView ID="gridRoutes" runat="server" AllowPaging="True" AutoGenerateColumns="False"
    DataSourceID="odsRoutes" onrowdatabound="gridRoutes_RowDataBound">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="chk_selector" runat="server"  AutoPostBack="true" OnCheckedChanged="chk_selector_CheckedChanged" Checked="false"/>
            </ItemTemplate>开发者_如何学Python
        </asp:TemplateField>
        <asp:BoundField DataField="Number" HeaderText="Number" 
            SortExpression="Number" />
        <asp:BoundField DataField="StartAddress" HeaderText="StartAddress" 
            SortExpression="StartAddress" />
        <asp:BoundField DataField="EndAddress" HeaderText="EndAddress" 
            SortExpression="EndAddress" />
        <asp:BoundField DataField="StopTime" HeaderText="StopTime" 
            SortExpression="StopTime" />
    </Columns>
</asp:GridView>


If you're happy to do it in jQuery, this should do the trick:

$('table[id$='gridRoutes'] :checkbox').first().attr('checked', true);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号