English 中文(简体)
更改GridView项的字体大小
原标题:Changing a GridView item s font weight
  • 时间:2010-10-27 17:03:13
  •  标签:
  • asp.net

I have a gridview that contains one linkbutton within itemtemplate. I bind this gridview with a table from my database that displays different items. When the gridview displays records and when the user clicks on an item of gridview then how can i change that item s fontweight to bold and change that same item s color.

最佳回答

不是100%确定,但您可以在创建所有使用的链接按钮时在客户端执行此操作

linkbutton.Attributes.Add(“onclick”、“setBoldandColor(this)”)

然后有一个javascript函数

function setBoldandColor(id) { //getElementById(id).style.font.bold=true; //change color }

问题回答

试试这样的方法:

        <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>

您可以使用jQuery并在客户端轻松完成这一切。。。

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

注意:这将更改整行的字体大小和颜色。如果你只想更改实际点击的文本,你可以删除.最接近的(“tr”),它就会起作用。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签