2 u011295626 u011295626 于 2014.08.12 21:13 提问

js按行操作gridview,gridview中有若干行数据

点击btn实现行变色,开始全无色,点击一次第一行变色,第二次点击第二行变色
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jsgrid.aspx.cs" Inherits="tryeccel.jsgrid" %>

<!DOCTYPE html>



无标题页

<br> $(document).ready(function () {</p> <pre><code> function setStatus(status) { var row = 0; var AllRows = document.getElementById(GridViewId).getElementsByTagName(&quot;tr&quot;); AllRows[row].style.background = System.Drawing.Color.Lime; $(&quot;button#btn1&quot;).click(function () { // $(&quot;input[type=radio]&quot;).attr(&#39;checked&#39;, false); // $(&quot;#Radio1&quot;).attr(&#39;checked&#39;, true); // $(&quot;#RadioButton1&quot;).attr(&#39;checked&#39;, true); $(&quot;#GridView1&quot;).eq(row).find(&#39;input&#39;).eq(status).attr(&#39;checked&#39;, true); row = row + 1; }) $(&quot;button#btn2&quot;).click(function () { AllRows[row].style.background = System.Drawing.Color.Lime; row = row + 1; }) } }) </code></pre> <p>


    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="273px" DataKeyNames="Sno">
        <Columns>
            <asp:BoundField DataField="Sno" HeaderText="Sno" SortExpression="Sno" ReadOnly="True" />
            <asp:BoundField DataField="Sname" HeaderText="Sname" SortExpression="Sname" />
            <asp:BoundField DataField="Sex" HeaderText="Sex" SortExpression="Sex" />
            <asp:BoundField DataField="Classno" HeaderText="Classno" SortExpression="Classno" />
            <asp:TemplateField HeaderText="单选">
                     <ItemTemplate>
                          <input type="radio" id="RadioName" name="RadioName" value='<%# Eval("Sno")%>' />
                     </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CheckSysConnectionString %>" SelectCommand="SELECT [Sno], [Sname], [Sex], [Classno] FROM [Students]"></asp:SqlDataSource>
    <button id="btn1"type="button" >选择</button>
    <button id="btn2"type="button" >变色</button>
</form>


Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!