RowDataBound function of GridView

后端 未结 2 1277
别跟我提以往
别跟我提以往 2020-12-12 01:15

I have a DataTable that contains 3 fields: ACount, BCount and DCount. If ACount < 0 then I need to displa

2条回答
  •  失恋的感觉
    2020-12-12 01:29

    This has worked for me.... I must be misunderstanding something so I had to replace angled brackets with [ or ] for the ASP so just be aware of that.

     [asp:TemplateField runat="server" HeaderText="Header"]
     [ItemTemplate]
     [asp:Label ID="theLabel" runat="server" Text='[%# Eval("DataSource").ToString() 
      %]'][/asp:Label]
     [/ItemTemplate]
     [/asp:TemplateField]
    
    
     protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
     {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label newLabel = (Label)e.Row.FindControl("theLabel");
    
            if (newLabel.Text.Length > 20) //20 is cutoff length
            {
                newLabel.Text = lbl.Text.Substring(0, 20);
    
                newLabel.Text += "...";
            }
        }
    }
    

提交回复
热议问题