<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                        CellPadding="4"  ForeColor="#333333" GridLines="None" 
                        DataKeyNames="tradecode" 
                        onselectedindexchanging="GridView1_SelectedIndexChanging"  OnRowDataBound="GridView1_RowDataBound"
                        SkinID="tradecode">
                        <RowStyle BackColor="#EFF3FB" />
                        <Columns>
                        
                            <asp:BoundField DataField="tradecode" HeaderText="商品编号" />
                            <asp:BoundField DataField="fullname" HeaderText="商品名称" />
                            <asp:BoundField DataField="type" HeaderText="商品型号" />
                            <asp:BoundField DataField="standard" HeaderText="商品规格" />
                            <asp:BoundField DataField="unit" HeaderText="商品单位" />
                            <asp:BoundField DataField="produce" HeaderText="商品产地" />
                            <asp:BoundField DataField="qty" HeaderText="库存数量" />
                            <asp:BoundField DataField="stockcheck" HeaderText="盘点数量" />
                        </Columns>
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <EditRowStyle BackColor="#2461BF" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>

解决方案 »

  1.   

    你是不是在GridView1_SelectedIndexChanging中做了什么,或者把选中颜色修改了,和未选中的颜色一样
      

  2.   

        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            string tradeCode = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
            string fullname = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
            Session["name"] = fullname;
            this.tBoxStock.Text = tradeCode;
        }    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
                 int i;
            //执行循环,保证每条数据都可以更新
            for (i = 0; i < GridView1.Rows.Count; i++)
            {
                //首先判断是否是数据行
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    //当鼠标停留时更改背景色
                    e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
                    //当鼠标移开时还原背景色
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                }
            }
        }
        protected void GridView1_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
        {
            string tradeCode = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
            string fullname = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
            Session["name"] = fullname;
            this.tBoxStock.Text = tradeCode;
        }
      

  3.   

    是可以的。
    应该是你哪里不经意变更了设置。
    你可以先拖一个新的GRIDVIEW控件,
    自己随意造些数据.再绑定(不指定列名)
    试下.应该是可以的.
    你再对比原来的控件,看是哪里设置不正常.
      

  4.   

      <Columns>
        
      <asp:BoundField DataField="tradecode" HeaderText="商品编号" />
      <asp:BoundField DataField="fullname" HeaderText="商品名称" />
      <asp:BoundField DataField="type" HeaderText="商品型号" />
      <asp:BoundField DataField="standard" HeaderText="商品规格" />
      <asp:BoundField DataField="unit" HeaderText="商品单位" />
      <asp:BoundField DataField="produce" HeaderText="商品产地" />
      <asp:BoundField DataField="qty" HeaderText="库存数量" />
      <asp:BoundField DataField="stockcheck" HeaderText="盘点数量" />
    <asp:ButtonField CommandName="Select" Text="Select" />
    </Columns>
      

  5.   

    悲剧,突然发现这是这个项目第一需要点击的。别的也不行。点击你加的那个select,有反应。那个触发的是什么方法啊
      

  6.   

      e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
      //当鼠标移开时还原背景色
      e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");这样设置的是TR的事件,你可以试下在TD上设置onmouseover 事件
      

  7.   

    我把变色删了,不要变色。我加变色就是为了实现选中一行。我想点击一行的任何单元格,都实现点击select的
      

  8.   


    protected void GridView_BulletinList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton lb1 = e.Row.FindControl("LinkButton_Del") as LinkButton;            lb1.Attributes.Add("onclick", " return confirm('确定要删除吗?')");
            }        
        }
      

  9.   

    我要的是,点击gridview的行。不是一个按钮