Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to limit the text and display full text with Read More button in grid view


What I have tried:

DataTable table=new DataTable();
           //GridView1.DataSource = table;
           string str2 = "select id,title,description from tbl_event order by id desc";
           obj.ds = obj.ret_ds(str2);
           GridView1.DataSource = obj.ds;
           GridView1.DataBind();
           int i = 0;
           foreach (DataRow row in table.Rows)
           {
               string x = row["description"].ToString();
               if (x.Length > 10)
               {
                   GridView1.Rows[i].Cells[0].Text = x.Substring(0, 10) + "<a href=EventDetail.aspx>Read More </a>";
               }
               i++;
               if (i >= table.Rows.Count)
               {
                   return;
               }
           }


But this code is not working.
Posted
Updated 29-Dec-16 23:39pm

1 solution

Well, you have to add TemplateFiled (another column of gridview). For farther details, please, see:
How to: Respond to Button Events in a GridView Control[^]
GridView.Columns Property (System.Web.UI.WebControls)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900