单击GridView控件中某一行后,如何在TextBox控件中显示该行是第几行(即第一行显示0,第二行显示1......)

解决方案 »

  1.   

    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> OleDbData md = new OleDbData("select * from 基本信息");
    DataTable dt = md.FillDataTable();
    md.Close();
    GridView1.DataSource = dt;
    GridView1.DataBind();
    for (int i = 0; i < GridView1.Rows.Count; i++)
    GridView1.Rows[i].Attributes.Add("onclick", "document.getElementById('TextBox1').value='" + GridView1.Rows[i].RowIndex.ToString() + "'");
    OleDbData类为数据库通用类。
      

  2.   

            <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 + "");
            }
        }