2010-10-27 55 views
0

我有一个gridview,它在itemtemplate中包含一个linkbutton。 我将这个gridview与我的数据库中的一个表格绑定,显示不同的项目。 当gridview显示记录,当用户点击一个gridview项时,我该如何将该项的fontweight更改为粗体并更改同一项目的颜色。更改GridView项目的字体重量

+1

我编辑了您的问题以取出“紧急”部分。 StackOverflow问题通常在不到2分钟的时间内回答,因此您不必为此担心。我认为,如果你在整个过程中发送“紧急”消息,你会对你的问题产生较少的兴趣。 – 2010-10-27 17:05:13

+1

**紧急信息:**没有人关心,如果你的问题是迫切的 – 2010-10-27 17:48:03

回答

0

不是100%肯定,但作为您创建的所有使用

linkbutton.Attributes.Add的了LinkBut​​ton,你可以做到这一点客户端(“点击”,“setBoldandColor(本)”)

则有javascript函数

函数setBoldandColor(id) //getElementById(id).style.font.bold=true; //改变颜色 }

+0

多数民众赞成在一个不错的主意,但我有我的linkbutton在gridview – 2010-10-27 17:12:09

+0

帮助一个新的家伙出来并评价我的答案? – 2010-10-27 17:13:50

+0

你可以在RowCreated Event上做到这一点看到这个论坛帖子http://www.velocityreviews.com/forums/t123457-how-to-add-attributes-to-gridview-buttonfields.html – 2010-10-27 17:19:48

0

尝试是这样的:

 <style type="text/css"> 
      .gridViewLink { 
       color:#CCCCCC; 
      } 
     </style> 

     <script type="text/javascript"> 
      var prevSelection = null; 

      function toggleStyle(currentSelection) { 
       if (prevSelection != null) { 
        prevSelection.style.fontWeight = 'normal'; 
        prevSelection.style.color = '#CCCCCC'; 
       } 
       currentSelection.style.fontWeight = 'bold'; 
       currentSelection.style.color = '#777777'; 
       prevSelection = currentSelection; 
      } 
     </script> 

     <asp:GridView ID="gvDemo" runat="server"> 
     <Columns> 
      <asp:TemplateField> 
       <ItemTemplate> 
        <asp:LinkButton ID="btnDemo" OnClientClick="toggleStyle(this);return false;" CssClass="gridViewLink" Text="Demo" runat="server" /> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
     </asp:GridView> 
0

你可以使用jQuery,做这一切在客户端比较容易......

$(function() { 
    $("#GridViewID_HERE a[id$=LinkButtonID_HERE]").click(function() { 
    $(this).closest("tr").css({ fontWeight: "bold", color: "red" }); 
    }); 
}); 

注意:这将改变整行的字体重量和颜色。如果您只想更改实际点击的文本,则可以删除.closest("tr"),它将起作用。