C# 无法从gridview中的TemplateField中获取文本
我有一个gridview: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
<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分钟才能创建问题。