本帖最后由 lincole 于 2009-11-17 10:27:07 编辑

解决方案 »

  1.   

    可以给Button的ArgumentValue属性绑定当前行的索引(数据库里的主键列),然后在后台的按钮OnCommand事件里用e.ArgumentValue就可以获得按钮绑定的数据了。
      

  2.   

    在DataGridView中设置一个隐藏列,记录是否选中。
    通过cellclick事件改变隐藏列的值。
    从而控制颜色。
      

  3.   

    在RowDateBound事件里写如下CS代码:    if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string headID = e.Row.Cells[0].Text.Trim();
            string modelstring = "javascript:changeRowColor(" + e.Row.RowIndex + ",'" + gvMainList.ClientID + "');";
        }";        //双击 事件
            e.Row.Attributes.Add("OnDblClick", modelstring);
            e.Row.Attributes.Add("onclick", "changeRowColor(" + e.Row.RowIndex + ",'" + gvMainList.ClientID + "');");
            //设置悬浮鼠标指针形状为"小手"
            e.Row.Attributes["style"] = "Cursor:hand";
        }
    上面的JS方法内容   function changeRowColor1( row,girdview)
       {   
           
           var GridView = document.getElementById(girdview);
           if(GridView!=null)
           {
              //GridView.rows[1].className ="RowStyle";
              for(i = 1;i < GridView.rows.length; i++)
              {   
                  if(i==row+1)
                  {
                     GridView.rows[i].className ="SelectedRowStyle1";
                   
                  }
                  else 
                  {
                    if(i%2==0)
                    {
                      GridView.rows[i].className ="RowStyleNo";
                    }
                    else
                    {
                      GridView.rows[i].className ="RowStyle";
                    }
                    
                 }
              }
           }
           else
           {
             return false;
           }
       }.SelectedRowStyle1
    {
    font-family: 宋体;
    font-size: 12px;
    border-style: none;
    background-color: #FF8282;
    color: #000000;
    font-weight: normal;
    height: 16px;
    }
    .RowStyleNo
    {
    border-style:none;
    border:1px;
    background-color: #F7F7F7;
    font-family: 宋体;
    font-size: 12px;
    color: #000000;
    height: 16px;
    }
    .RowStyle
    {
    border-style:none;
    border:1px;
    background-color: #F1F8FE;
    font-family: 宋体;
    font-size: 12px;
    font-weight:normal;
    color: #000000;
    height: 16px;

    }
      

  4.   

    后台
    protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
    e.Row.Attributes.Add("onclick", "setIndexValue("+e.Row.DataItemIndex+");");
    }
    }
    前台
    放一个hidden
    <input type="hidden" id="selectedindex" runat="server" />
    js函数
    function setIndexValue(index)
    {
    document.getElementById("selectedindex").value = index;
    }
    后台button事件
    protected void button1_Click(object sender, EventArgs e)
    {
    int index = Convert.ToInt32(selectedindex.Value);
    if(index<gridview.Rows.Count)
    {
    GridViewRow row = gridview.Rows[index];
    }
    }