Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从gridview中的TemplateField中获取文本_C#_Asp.net_Gridview - Fatal编程技术网

C# 无法从gridview中的TemplateField中获取文本

C# 无法从gridview中的TemplateField中获取文本,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个gridview: <asp:GridView runat="server" ID="gv_tList" OnRowDataBound="gv_tList_RowDataBound"> <Columns> <asp:BoundField DataField="taskID" HeaderText="taskID" /> <asp:TemplateField HeaderT

我有一个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>
e、 Row.Cells[0]。Text返回文本字符串,但e.Row.Cells[1]。Text返回。有人知道如何从单元格中获取文本吗?

您可以在side TemplateField中声明标签,这样您就可以尝试类似的方法了

   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;
        }
    }
您可以在side TemplateField中声明标签,这样您就可以尝试这样的操作

   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;
        }
    }

@总统卡马乔你的欢迎标记为回答,如果你认为这有帮助的话…:是的,ofc,但我必须等15分钟才能创建问题。@PresidentCamacho你的欢迎标记为回答,如果你认为这有帮助的话…:是的,ofc,但我必须等15分钟才能创建问题。