代码之家  ›  专栏  ›  技术社区  ›  Ayush

使第一列和最后一列不可单击

  •  0
  • Ayush  · 技术社区  · 15 年前

    下面是一些代码(来自.cs文件):

    if(e.Row.RowType == DataControlRowType.DataRow)
             {
                e.Row.BackColor = TRADER_BACKCOLOR;
                e.Row.Cells[0].Font.Bold = true;
                e.Row.Attributes.Add("onmouseover", "style.backgroundColor = 'Silver'");
                e.Row.Attributes.Add("onmouseout", "style.backgroundColor = '" + TRADER_HEX + "'");
                e.Row.Attributes.Add("onclick", "RowClick(this, '" + e.Row.Cells[0].Text + "');");
    

    function RowClick(caller, id)
          {
             if(document.getElementById(id).style.display == "block")
             {
                    if(last != "" && parent == id)
                    {
                        HideDetailed();
                    }
                document.getElementById(id).style.display = "none";
             }
             else
             {
                document.getElementById(id).style.display = "block";
             }
          }
    
    2 回复  |  直到 15 年前
        1
  •  1
  •   Jagd Dai    15 年前

    你必须事先知道你把桌子绑在上面的东西的数量。

    // minus one since the RowIndex is 0-based
    int total = whateverYouAreBindingTo.Count - 1;
    

    然后在你的事件中或者你添加OnClick事件的地方。。。

    if (e.Row.RowIndex > 0 && e.Row.RowIndex < total)
       e.Row.Attributes.Add("onclick", "RowClick(this, '" + e.Row.Cells[0].Text + "');");
    
        2
  •  0
  •   EJC    15 年前

    我不会为不想单击的行添加属性,例如:

    if(e.Row.RowType == DataControlRowType.DataRow)
    {
    
        e.Row.BackColor = TRADER_BACKCOLOR;
        e.Row.Cells[0].Font.Bold = true;
        e.Row.Attributes.Add("onmouseover", "style.backgroundColor = 'Silver'");
        e.Row.Attributes.Add("onmouseout", "style.backgroundColor = '" + TRADER_HEX + "'");
       if (e.Row.RowIndex != 0 && e.Row.RowIndex != yourGridView.Rows.Count - 1)
       {
         e.Row.Attributes.Add("onclick", "RowClick(this, '" + e.Row.Cells[0].Text + "');");
       }