无法从网格视图中的 TemplateField 获取文本

Can't get text from a TemplateField within a gridview

我有这个网格视图:

<asp:GridView runat="server" ID="gv_tList" OnRowDataBound="gv_tList_RowDataBound">
        <Columns>
            <asp:BoundField DataField="taskID" HeaderText="taskID" />      
            <asp:TemplateField HeaderText="Description" >
                <ItemTemplate>
                    <asp:Label ID="descr" runat="server" Text='<%# Eval("Description") %>' ToolTip='<%# Eval("descr") %>' />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
</asp:GridView>

和这段代码:

   protected void gv_tList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string taskID = e.Row.Cells[0].Text;
            e.Row.Cells[1].Text = e.Row.Cells[1].Text.Length > 40 ? e.Row.Cells[1].Text.Substring(0, 40) + ".." : e.Row.Cells[1].Text;
        }
    }

e.Row.Cells[0].Text returns 一个文本字符串但是 e.Row.Cells[1].Text returns ""。有人知道如何从单元格中获取文本吗?

你在 TemplateField 边声明 Label 所以你可以尝试这样的事情

   protected void gv_tList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
           Label descr=(Label)e.Row.FindControl("descr");
           string Mydescr=descr.Text
           string taskID = e.Row.Cells[0].Text;
           descr.Text = descr.Text.Length > 40 ? 
           descr.Text.Substring(0, 40) + ".." : descr.Text;
        }
    }