this.GridView1.FindControl("ControlID");或者通过JQuery查看客户端id在前台获得值。

解决方案 »

  1.   

    前台gridview <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCreated="GridView1_RowCreated"
                    OnRowDataBound="GridView1_RowDataBound" OnSorting="GridView1_Sorting" DataKeyNames="id">
                    <Columns>
                        <asp:TemplateField HeaderText="序号" SortExpression="Id">
                            <ItemTemplate>
                                <%# (this.AspNetPager1.CurrentPageIndex - 1) * this.AspNetPager1.PageSize + Container.DataItemIndex + 1%>
                            </ItemTemplate>
                            <ItemStyle Wrap="True" />
                            <HeaderStyle Wrap="False" />
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                学号</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblxh" runat="server" Text='<%#Eval("StuNo") %>'></asp:Label></ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="StuName" HeaderText="姓名" SortExpression="StuName" />
                        <asp:BoundField HeaderText="课程名称" SortExpression="Gender" DataField="LessonName" />
                        <asp:BoundField DataField="ClassName" HeaderText="班级名称" SortExpression="ClassName" />
                        <asp:BoundField HeaderText="录入次数" />
                        <asp:TemplateField HeaderText="成绩类型"></asp:TemplateField>
                        <asp:TemplateField HeaderText="考核成绩">
                            <ItemTemplate>
                                <asp:DataList ID="dtlist1" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dtlist1_ItemDataBound">
                                    <ItemTemplate>
                                        <table border="0" cellspacing="0" cellpadding="0" width="99%"">
                                            <tbody>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblxm" runat="server" Text='<%#Eval("Contents") %>'></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td valign="top" align="left">
                                                        <asp:TextBox ID="txtboxfenshu" runat="server" Width="50px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </ItemTemplate>
                                </asp:DataList>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>后台cs
     protected void dtlist1_ItemDataBound(object sender, DataListItemEventArgs e)
            {
                string whicht = "";
                string whichid = "";
                string xuehao = ((Label)this.GridView1.FindControl("lblxh")).Text;
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    string totalid = "txtboxfenshu";
                    ((TextBox)e.Item.FindControl("txtboxfenshu")).Visible = true;
                    whicht = ((TextBox)e.Item.FindControl("txtboxfenshu")).ClientID.ToString();
                    whichid = "txtboxfenshu";
                    ((TextBox)e.Item.FindControl("txtboxfenshu")).Attributes.Add("onfocusout", "WriteData('" + e.Item.ItemIndex + "','" + whicht + "','" + whichid + "','" + totalid + "',this)");
                }
            }但是这么写这一句会报错,    string xuehao = ((Label)this.GridView1.FindControl("lblxh")).Text;  提示未将对象引用设置到对象的实例。说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 494:            string whicht = "";
    行 495:            string whichid = "";
    行 496:            string xuehao = ((Label)this.GridView1.FindControl("lblxh")).Text;
    行 497:            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    行 498:            {
      

  2.   


    目测应该一级一级的获取
    ((Label)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
      

  3.   

    谢谢各位的支持   我的问题已解决   我在外层rowbound方法中  增加一列,在子层中取出就可以了
      

  4.   

    读一下10年前的asp.net教程。http://wenku.it168.com/d_000702238.shtml
      

  5.   

    内层的记录与外层记录一定有相关联的。
    显示内层记录中的sql,就包含了外层记录的主键或是你想要的字段记录。