0

当单击特定的网格视图行时,我试图将背景颜色应用于网格视图行。

 <script type="text/javascript">
        function ChangeRowColor(objref) {
            objref.style.backgroundcolor = "red";
        }
    </script>


 <asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
        runat="server" AutoGenerateColumns="false" OnRowCreated="GridView1_RowCreated">
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
            <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
        </Columns>

</asp:GridView>

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            string rowID = String.Empty;

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", "ChangeRowColor(this)");
            }

        }

但是,当我点击该行时,什么都没有发生..请帮助..

4

1 回答 1

2

你把案子弄错了。

它应该如下所示。

objref.style.backgroundColor = "red";
于 2013-09-23T09:59:31.543 回答