简体   繁体   中英

how to use substring in linq c# and also bind convert html tag in plan text. issue in binding GridView in asp.net

Hello Im trying to bind Grid view with linq query class that was working good but have to solve one issue in my code is below.

 DataClassesDataContext con = new DataClassesDataContext(con);
 var q = from v in con.View_tabel
                 where v.Id == WeekId 
                 select new { v.Id, v.WeekId, v.DayId, v.Title,
                         v.Description, v.ImageUrl,  v.WeekDayType };          
        GridView.DataSource = q;            
        GridView.DataBind();

hew is a code of conver html to plan text below how can i use this class in linq

public static string GetTextonly(string editorcontent)
    {
        string strtext = "";
        strtext = Regex.Replace(editorcontent, @"<(.|\n)*?>", string.Empty);
        return strtext;
    }

Im binding GridView with this Linq code and it working but i want to add few code in it for band a html tag Description in plan text and also us a substring to make a Description detail in short word around 200 words please modify my this code which will help me to bind Description HTML tags in plan Text and also with suing substring method

Thank you

Did you try to add GetTextonly(v.Description) in your select?

For this you need to name them to prevent the error of: Error Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

This means that you need to name your anonymous type's properties that cannot be inferred. Check out this article as it will help you with Anonymous Types (C# Programming)

 var q = from v in con.View_tabel
                 where v.Id == WeekId 
                 select new { 
                              name                 = v.Id, 
                              week                 = v.WeekId, 
                              day                  = v.DayId, 
                              titleText            = v.Title,
                              descriptionText      = v.Description, 
                              descriptionClearText = GetTextonly(v.Description),
                              image                = v.ImageUrl,  
                              weekDay              = v.WeekDayType 
                            };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM