需求是这样的,有一个gridview,全部是boundfield绑定的数据源,没有任何模板列。
              就单单的一个gridview。
              现在就是鼠标单击任何一行,可以获取这行的某个字段或者整个行的信息。请各位大哥大姐们,帮忙指点一下啊,3Q you!

解决方案 »

  1.   

    <asp:TemplateField HeaderText="组名称">
                                    <ItemTemplate>
                                        
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("col0") %>' ></asp:Label>
                                        <asp:LinkButton ID="a" runat="server" CommandName="b"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
    protected void gvColorGroup_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    LinkButton lbtn = (LinkButton)e.Row.FindControl("a");
                    e.Row.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(lbtn, ""));
                    e.Row.Attributes.Add("style", "cursor:pointer");
                }
            }
            protected void gvColorGroup_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                GridViewRow curgvr = (GridViewRow)((LinkButton)e.CommandSource).Parent.Parent;
                Label lbl = (Label)curgvr.FindControl("Label1");
                Response.Write(lbl.Text);
                if (e.CommandName=="b")
                {
                    FillColor(int.Parse(lbl.Text));
                }
            }模板列隐藏就行了,
      

  2.   

    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");
                    //单击行的任意列会自动选中此行
                    e.Row.Attributes.Add("onclick", "__doPostBack('GridView1','Select$" + e.Row.RowIndex + "')");
                }
            }
      

  3.   

    <asp:GridView ID="GridView5" runat="server" AutoGenerateColumns="False" onrowdatabound="GridView5_RowDataBound" >
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <%#DataBinder.Eval(Container,"DataItem.ID") %>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            </asp:GridView>
            <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>protected void GridView5_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("style", "cursor:pointer");
                e.Row.Attributes.Add("onclick", "document.getElementById('TextBox5').value=" + e.Row.RowIndex + "");
            }
        }
      

  4.   

    用惯了repeater  ,学习下gridview
      

  5.   


    谢谢哦,理解了你的代码,我修改了一下哦,3Q you  !!!!
      

  6.   

    protected void GridView5_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("style", "cursor:pointer");
                e.Row.Attributes.Add("onclick", "document.getElementById('TextBox5').value=" + e.Row.RowIndex + "");
            }
        }
    把e.Row.RowIndex改成e.Row.Cell["要获取某一列的字段"].Text;就OK了!
      

  7.   

    请问__doPostBack这个函数应该怎么定义啦,我在后面定义的为什么不行求指点