.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Using Html.Truncate in Webgrid Column

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net
I'm using the Html.Truncate function from the MvcMusicStore tutorial (page 5) and I want to use it in a Webgrid column to trim some text. However I can't get the syntax correct to get the Html.Truncate function to work with a string in my Webgrid. My (now experimental) Webgrid looks like this:
@{ var grid = new WebGrid(Model, canPage: true, canSort: true); @grid.GetHtml(columns: grid.Columns( grid.Column("Comment", "Comment1", format: @<text>@Html.Truncate("Test string", 4)</text>), grid.Column("Comment", "Comment2", format: @<text>@Html.Truncate(@item.Comment, 8)</text>), grid.Column("Comment", "Comment3", format: @<text>@item.Comment</text>) )); }
 The code for column "Comment1" and "Comment3" is working but the code in "Comment2" is not working. The error message I get is
Description: An error occurred during the compilation of a resource required to service this request. 
Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for
'System.Web.Helpers.WebGrid.Column(string, string

View Complete Post

More Related Resource Links

Rendering data with HTML tags in the DD Gridview for a selected column


I am having trouble finding out where and how to HTML Encode a cell's data on the Dynamic Data (v4.0) gridview of List.aspx.  As a simple case, suppose I have formatted cell data that is A<br/>B in the DB.    Obviously, I want A stacked on B in the cell.

It seems gridView1.HtmlEncode = true has gone away.

So maybe I'll try to catch it on the RowDataBound event:

protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)

            if (e.Row.RowType == DataControlRowType.DataRow)
                // Html Encode the cells


but this event never fires?

Has anyone figured out how to properly render HTML tags data in the List.aspx's GridView1? 

If I figure this out, then I can add a MetaAttribute called something like [EncodeAsHtml(true)] and be on my way.  Thanks!

Html column with ListaData.svc + linq + custom webpart

Hello Everybody, 

I'm developing a custom web site with sharepoint, so, I have one custom list that has a html column type. 
I'd like to get this column with linq and ListData.svc, on my custom webpart. But, when I called the method, it's not return this column.

So, my question is:  Can I get a Html column by listdata.svc ?


MVC 3 Beta WebGrid, T4MVC and Custom Column



I have the following MVC 3 Beta Grid:

  @grid.GetHtml(tableStyle: "Grid",  
                       columns: grid.Columns(  
                         grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.Id })),
                         grid.Column(format: (item) => Html.ActionLink("Delete", MVC..User.Delete(item.Id)))

I am trying to solve three problems:

1 - Use T4MVC. On the last column, User.Delete, I get the following error:

     The best overloaded method match for 'System.Web.Helpers.WebGrid.Column(string, string, System.Func<dynamic,object>, string, bool)' has some invalid  arguments

2 - Have the two ActionLinks, Edit and Delete on the same column, and have a CSS class for that column. Something like:

   grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.Id }) + Html.ActionLink("Delete", MVC..User.Delete(item.Id)))

And make the CSS cl

Call a SQL Server function(cleans html tags) on a derived column in SSIS


I have a task to move table having "text" data type for a column from SQL Server to CSV file so while transfering the data using SSIS I want to perform Cleanup on this column such as removing HTML tags, White spaces etc and then transfer it. Note: I dont have any option to store the table in the staging database as I will be running it on the production server directly.

Can any one help me accomplish this task???





How to use html helpers in WebGrid


Hi all,

How can use html helpers in WebGrid Columns.

I tried like this. but there was error like the best overloads method parameter

    ViewBag.Title = "News";
    Layout = "~/Views/Shared/_Layout.cshtml";
@model IQueryable<Connect.Models.News>
    News Listing</h2>
    var grid = new WebGrid(Model);
    grid.GetHtml(columns: grid.Columns(
        grid.Column("ID", "ID"),
        grid.Column("Name", "Name", format: @<b>@item.Name</b>),
        grid.Column("Seourl", "Given Seourl"),
        grid.Column( header: "English", format: Html.RouteLink("Entry", new{ })  ),

I'm referring to

        grid.Column( header: "English", format: Html.RouteLink("Entry", new{ })  ),

THanks a lot!

WebGrid: column definition - Set 'style:' parameters depending on value


I have a list of objects (List<myObject>) which I pass to a webGrid. I would like to set cells for a column of the table to a specific value depending the object's 'StatusColor' property. Something like

List<myObject> myObjectList = 
WebGrid webGrid = new WebGrid(source: myObjectList, ..);
columns: webGrid.Columns
webGrid.Column("Status", "Status", format: @<text>@item.StatusName</text>, style:



But for some reason, I get "cannot convert from 'lambda expression' to 'string'". When I remove the @<text> suround the item property, I get "the name '@item' does not exists in the current context"

For the 'format:' part, it works fine.

ASP.NET, HTML, JavaScript Snippet Support (VS 2010 and .NET 4.0 Series)

This post covers another useful improvement in VS 2010 - HTML/ASP.NET/JavaScript snippet support. Snippets allow you to be more productive within source view by allowing you to create chunks of code and markup that you can quickly apply and use in your application with a minimum of character typing.

Visual Studio has supported the concept of "snippets" for VB and C# in previous releases - but not for HTML, ASP.NET markup and JavaScript. With VS 2010 we now support snippets for these content types as well.

Maintain HTML Radio Button Selection Inside GridView After Postback

Long time ago I wrote an article about getting the value of the selected RadioButtons inside the GridView control. The code did not addresssed the postback issue which means that the selected radio button was cleared after the postback occurs.

Tooltip for GridView Column Headers (ASP.Net)

I just wanted to add auto tooltips for my GridView headers. There are couple of ways but I don't want to use javascript and wanted to use simple 'title' attribute. It took couple of hours to get the working code supporting sortable columns. I thought it will be very useful for others. Here's the code and logic behind it.

Multiple Column Dropdownlist for the ASP.NET DataGrid

Based on my previous control "Multiple Column DropDownList for ASP.NET", I received many emails asking for the same control to be used in the DataGrid for web applications. Here we go.. This control can be used as the regular MS DropDownList in the DataGrid and also as a regular dropdownlist. It has all the properties, like DataTextField, DataValueField, DataSource, SelectedIndex etc. The download file contains the samples both in VB.NET and C#. In this sample, I have used the Northwind database of SQL Server.

Rendering ASP.NET Script References into the Html Header

One thing that I've come to appreciate in control development in ASP.NET that use JavaScript is the ability to have more control over script and script include placement than ASP.NET provides natively. Specifically in ASP.NET you can use either the ClientScriptManager or ScriptManager to embed scripts and script references into pages via code.

Alternating row background for first column of a report


is there a way to make the first column of a report use the an alternating background color? 

I have the background color set for the entire row however it does not work for the first column if the color is set to an expression.  If I just set it to a color i.e. red it works just fine. If I insert a dummy column to the left it works just fine (but the dummy column does not work, presumably because it is first??).

In the file below only the textbox for part number does not show an alternating background.  All others work correctly.

                    <Textbox Name="PartNumber">

Use a column as parameter for a sds in another column; gridview


Hola, I have a gridview which is bound to a sds which returns 7 columns and I added two columns from the GUI.  What I want is to fill up the 9th column with DDLs and these  DDLS will get their data from a different sds which is using a stored procedure with a single parameter.  I created the 9th row, used template field, made the sds for 9th row, the stored_procedure, threw a DDL in Item template and all  I need now is to pass a parameter in the first column to the sds in the 9th column.  I can code this but i'm getting tired of aspx.cs :) and would like to do it from the GUI.

Getting value of Html.TextBoxFor(m => m.name)


Hi All,

I am new to Asp.net MVC 2. I am unable to get value for Html.TextBoxFor(m = > m.name) in view. I can get this value in Controller.

How to get this value in view.

Please help.

Embed Youtube inside Ajax Html Editor- problem



When inserting a simple embed of youtube inside the ajax editor, on firefox and chrome problems occur. On the other hand on internet explorer 8 everything works fine. I found this solution http://www.nopcommerce.com/boards/t/4228/bug-in-ajax-html-editor.aspx . 

My question is where do I find the DesignPanel.pre.js ?


Roderick Vella

Pass a grid column value to a Modal


Hi, I have a requirement to hide a field called details on a gridview and show it in a jQuery modal dialog when users click on the Customer ID hyperlink. This grid is created programmatically. I will be hiding the details column via the CSS display:none property. Does some one know how can I pass the grid's selected hidden column value to the modal? Here is some of the code I started:

            GridView mygrid = new GridView();
            //.....................................More columns code for the grid

            //Here is where I need to pass the Details column value associated with the customer ID field selected to the Modal and open the Modal dialog.            
            HyperLinkField linkField = new HyperLinkField();
            string[] dataNavigateUrlFields = { "CustomerID" };
            linkField.DataTextField = "CustomerID";

Re-positioning an HTML container with javascript onresize with a Master page.


I have an HTML <div> container that I float to the right of a gridview.  When the browser window is maximized, it looks fine.  When minimized, the gridview positions below the floating container and most of the data is pushed off the bottom of the browser - you have to scroll down to see it.

If I position the floating container above the gridview it looks fine in a minimized window, but looks real bad when maximized.

What I want to do is use a javascript: onresize event to re-position the floating container up or down depending on the window.inner.width AND do it with a Master/Content page structure AND do it for only the one page where needed.

I can capture the onresize event and display the window dimensions but haven't figured-out how to do it with a Content page that still uses the Master page.  I think I'm having a very "thick" week...

- Tinker


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend