This question is locked. New answers and comments are not allowed.
Hi,
I am trying to use an email column in my Grid. I need to have my email column so that I can click on it and send an email. Are there any samples on how this is done ? I am trying something like this, and i think this is incorrect ?
I am trying to use an email column in my Grid. I need to have my email column so that I can click on it and send an email. Are there any samples on how this is done ? I am trying something like this, and i think this is incorrect ?
columns.Add(o => o.cEmail).Width(120).Title(
"Email").Width(150)
.Format(Html.Mailto(
"emaila", o => o.cEmail));
Thanks
14 Answers, 1 is accepted
0
Hi IQworks,
Please review this online demo. It uses templates. You can use the same approach to generate the required javascript to send the required email.
Best wishes,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Please review this online demo. It uses templates. You can use the same approach to generate the required javascript to send the required email.
Best wishes,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
IQworks
Top achievements
Rank 1
answered on 16 Feb 2010, 02:36 AM
Hi Georgi,
If its true that template columns only work in server binding mode, then do I need another type of example ?
http://www.telerik.com/community/forums/aspnet-mvc/grid/no-support-for-ajax-delete.aspx#996881
I am using AjaxBinding ?
I tried many variations of this code ,
and the error I keep getting (with line 13 highlighted - columns.Add(c => { )
Probably something I am overlooking ?
Also, this is how I tried it with the Mailto code ?
thanks.
If its true that template columns only work in server binding mode, then do I need another type of example ?
http://www.telerik.com/community/forums/aspnet-mvc/grid/no-support-for-ajax-delete.aspx#996881
I am using AjaxBinding ?
I tried many variations of this code ,
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<BCAnalytics.Models.CompanyVM>>" %> |
| <p><%= Html.ActionLink((String)Resources.BCAResources.stdClose, "Index", "Work", new { workindex = 0 }, null)%></p> |
| <%= Html.Telerik().Grid(Model) |
| .Name("CompanyGrid") |
| .Columns(columns => |
| { |
| columns.Add(o => o.cMemberNo).Width(30) ; |
| columns.Add(o => o.cCompanyNo).Width(30); |
| columns.Add(o => o.cCompanyName).Width(175).Title((string)Resources.BCAResources.coxCompany); |
| columns.Add(o => o.cPhone).Title((string)Resources.BCAResources.stdPhone).Width(75); |
| columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100); |
| // This is from the example you gave Georgi |
| columns.Add(c => { |
| %> |
| <img |
| alt="<%= c.cCompanyNo %>" |
| src="<%= Url.Content("~/Content/images/Icons/add.gif") %>" |
| /> |
| <% |
| }); |
| columns.Add(o => o.cEmail).Width(120).Title((string)Resources.BCAResources.stdEmail).Width(150); |
| columns.Add(o => o.cDateUpdated).Format("{0:MM/dd/yyyy}").Width(85).Title((string)Resources.BCAResources.stdUpdated); |
| columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdEdit, "Index", "Work", new { workindex = 3, OtherParms = "{0}" }, null).ToString()).Encoded(false).Title("").Width(32); |
| columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdDelete, "CompanyDelete", new { Id = "{0}" }, null).ToString()).Encoded(false).Title("").Width(50); |
| }) |
| .Ajax(settings => settings.Action("_AjaxBindingCompany", "Company")) |
| .Pageable() |
| .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn)) |
| .Scrollable(scrolling => scrolling.Height(200)) |
| .Filterable() %> |
| <p><%= Html.ActionLink((String)Resources.BCAResources.coxFormEntry, "Index", "Work", new { workindex = 2, OtherParms = "" }, null)%></p> |
and the error I keep getting (with line 13 highlighted - columns.Add(c => { )
| Server Error in '/' Application. |
| -------------------------------------------------------------------------------- |
| Compilation Error |
| 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: CS1525: Invalid expression term ')' |
| Source Error: |
| Line 11: columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100); |
| Line 12: |
| Line 13: columns.Add(c => { |
| Line 14: %> |
| Line 15: <img |
Probably something I am overlooking ?
Also, this is how I tried it with the Mailto code ?
| columns.Add(o => { |
| %> |
| <a href="mailto:<%=o.cEmail%>"><%=o.cEmail%></a> |
| <% |
| }); |
thanks.
0
Hi IQworks,
When using templates you cannot use <%= %> blocks. You must use <% %> and call the Render() method of the grid. This is the reason for the compilation error you are getting.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
When using templates you cannot use <%= %> blocks. You must use <% %> and call the Render() method of the grid. This is the reason for the compilation error you are getting.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
IQworks
Top achievements
Rank 1
answered on 16 Feb 2010, 07:21 PM
Hi Atanis,
Here is the code now with Render() and <% %>...
Here is he result of several variations of the suggested fix with Render() ....
Next variation ....
Last variation (original one, but with Render() - just curiosity)...
Line 12 keeps getting highlighted even with the variations of <% %> on line 14 ? Am I not understanding your suggestion again ?
thanks again
Here is the code now with Render() and <% %>...
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<BCAnalytics.Models.CompanyVM>>" %> |
| <p><%= Html.ActionLink((String)Resources.BCAResources.stdClose, "Index", "Work", new { workindex = 0 }, null)%></p> |
| <%= Html.Telerik().Grid(Model) |
| .Name("CompanyGrid") |
| .Columns(columns => |
| { |
| columns.Add(o => o.cMemberNo).Width(30) ; |
| columns.Add(o => o.cCompanyNo).Width(30); |
| columns.Add(o => o.cCompanyName).Width(175).Title((string)Resources.BCAResources.coxCompany); |
| columns.Add(o => o.cPhone).Title((string)Resources.BCAResources.stdPhone).Width(75); |
| columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100); |
| columns.Add(o => { |
| %> |
| <a href="mailto:<%o.cEmail%>"><%o.cEmail%></a> |
| <% |
| }); |
| columns.Add(o => o.cDateUpdated).Format("{0:MM/dd/yyyy}").Width(85).Title((string)Resources.BCAResources.stdUpdated); |
| columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdEdit, "Index", "Work", new { workindex = 3, OtherParms = "{0}" }, null).ToString()).Encoded(false).Title("").Width(32); |
| columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdDelete, "CompanyDelete", new { Id = "{0}" }, null).ToString()).Encoded(false).Title("").Width(50); |
| }) |
| .Ajax(settings => settings.Action("_AjaxBindingCompany", "Company")) |
| .Pageable() |
| .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn)) |
| .Scrollable(scrolling => scrolling.Height(200)) |
| .Filterable() |
| .Render(); %> |
| <p><%= Html.ActionLink((String)Resources.BCAResources.coxFormEntry, "Index", "Work", new { workindex = 2, OtherParms = "" }, null)%></p> |
Here is he result of several variations of the suggested fix with Render() ....
| Server Error in '/' Application. |
| -------------------------------------------------------------------------------- |
| Compilation Error |
| 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: CS1525: Invalid expression term ')' |
| Source Error: |
| Line 10: columns.Add(o => o.cPhone).Title((string)Resources.BCAResources.stdPhone).Width(75); |
| Line 11: columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100); |
| Line 12: columns.Add(o => { |
| Line 13: %> |
| Line 14: <a href="mailto:<%o.cEmail%>"><%o.cEmail%></a> |
Next variation ....
| Server Error in '/' Application. |
| -------------------------------------------------------------------------------- |
| Compilation Error |
| 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: CS1525: Invalid expression term ')' |
| Source Error: |
| Line 10: columns.Add(o => o.cPhone).Title((string)Resources.BCAResources.stdPhone).Width(75); |
| Line 11: columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100); |
| Line 12: columns.Add(o => { |
| Line 13: %> |
| Line 14: <a href="mailto:<%o.cEmail%>"><%=o.cEmail%></a> |
Last variation (original one, but with Render() - just curiosity)...
| Server Error in '/' Application. |
| -------------------------------------------------------------------------------- |
| Compilation Error |
| 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: CS1525: Invalid expression term ')' |
| Source Error: |
| Line 10: columns.Add(o => o.cPhone).Title((string)Resources.BCAResources.stdPhone).Width(75); |
| Line 11: columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100); |
| Line 12: columns.Add(o => { |
| Line 13: %> |
| Line 14: <a href="mailto:<%=o.cEmail%>"><%=o.cEmail%></a> |
| Source File: c:\IQSys\BCAnalytics\BCAnalytics\Views\Company\CompanyGrid.ascx Line: 12 |
Line 12 keeps getting highlighted even with the variations of <% %> on line 14 ? Am I not understanding your suggestion again ?
thanks again
0
IQworks
Top achievements
Rank 1
answered on 16 Feb 2010, 08:58 PM
Also, here are snap shots of some intellisence ....
Is there any documentation anywhere that talks about how "Render()" works ? and/or how template colums in MVC work ? I dont want to waste your time if there is something I can read that will help me understand things a little better ?
I am not sure of how to work with this current issue though,
thanks again.
Is there any documentation anywhere that talks about how "Render()" works ? and/or how template colums in MVC work ? I dont want to waste your time if there is something I can read that will help me understand things a little better ?
I am not sure of how to work with this current issue though,
thanks again.
0
Hello IQworks,
The column help topic is here. And this is our online example for using templates.
In you case you should be using <%= o.cEmail %> instead of <% o.cEmail %>. There is a subtle difference between using <%= %> vs. <% %> - <%= %> automatically outputs the value of the expression (e.g. o.cEmail) in the output using Response.Write whilst <% %> embeds some executable code which must output values manually using Response.Write.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
The column help topic is here. And this is our online example for using templates.
In you case you should be using <%= o.cEmail %> instead of <% o.cEmail %>. There is a subtle difference between using <%= %> vs. <% %> - <%= %> automatically outputs the value of the expression (e.g. o.cEmail) in the output using Response.Write whilst <% %> embeds some executable code which must output values manually using Response.Write.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
IQworks
Top achievements
Rank 1
answered on 18 Feb 2010, 10:06 PM
Hi Atanas,
Sorry if I am not paying attention to something ?
In the previous post I tried to use both variations of <%= %> and <% %>, and, I tried again today, along with trying to use "{0}", but still the same error ?
I also noticed that in the sample link you provided, they did not use Render() ?
When I tried to use Render() today, I was getting "Cannot implicitly convert type 'void' to 'object' " error.
thanks as usual for your time
0
Hi IQworks,
This code:
<a href="mailto:<%o.cEmail%>"><%o.cEmail%></a>
should be made like this:
<a href="mailto:<%=o.cEmail%>"><%=o.cEmail%></a>
.Render() is required every time you are using server side expressions (<% or <%=) in your grid declaration:
<% Html.Telerik().Grid().Render(); %>
All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
This code:
<a href="mailto:<%o.cEmail%>"><%o.cEmail%></a>
should be made like this:
<a href="mailto:<%=o.cEmail%>"><%=o.cEmail%></a>
.Render() is required every time you are using server side expressions (<% or <%=) in your grid declaration:
<% Html.Telerik().Grid().Render(); %>
All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
IQworks
Top achievements
Rank 1
answered on 03 Mar 2010, 11:44 PM
Hi,
Sorry for not getting back sooner, I have been working on some other priorities.
I think the issue has something to do with the fact that I am trying to use template columns within this Ajax bound grid ?
Your last suggestion <a href="mailto:<%=o.cEmail%>"><%=o.cEmail%></a> still gave me the same Invalid expression term ')' error.
However, I tried this - columns.Add(o => o.cEmail).Format(Html.Mailto("Email", "{0}")); The results are in the attatchment. The very first row has an actual email address iqwork@test.com. As you can see, and, it is readonly. The second row shows "mailto:">Email", which is the default because the 2nd row has no email test data. And the third row shows what should be "q' (NOT A FULL EMAIL ADDRESS, JUST A ONE CHARACTER TEST IN THE DATA RECORD EMAIL FIELD).
This is my current grid code.
Thanks again for your help.
Sorry for not getting back sooner, I have been working on some other priorities.
I think the issue has something to do with the fact that I am trying to use template columns within this Ajax bound grid ?
Your last suggestion <a href="mailto:<%=o.cEmail%>"><%=o.cEmail%></a> still gave me the same Invalid expression term ')' error.
However, I tried this - columns.Add(o => o.cEmail).Format(Html.Mailto("Email", "{0}")); The results are in the attatchment. The very first row has an actual email address iqwork@test.com. As you can see, and, it is readonly. The second row shows "mailto:">Email", which is the default because the 2nd row has no email test data. And the third row shows what should be "q' (NOT A FULL EMAIL ADDRESS, JUST A ONE CHARACTER TEST IN THE DATA RECORD EMAIL FIELD).
This is my current grid code.
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<BCAnalytics.Models.CompanyVM>>" %> |
| <h3><%= Html.ActionLink((String)Resources.BCAResources.stdClose, "Index", "Work", new { workindex = 0 }, null)%> |
| <br /> |
| <i style="color:Red;"><%=Session["iqResult"]%> </i> </h3> |
| <%= Html.Telerik().Grid(Model) |
| .Name("CompanyGrid") |
| .Columns(columns => |
| { |
| // columns.Add(o => o.cMemberNo).Width(30) ; |
| // columns.Add(o => o.cCompanyNo).Width(30); |
| columns.Add(o => o.cCompanyName).Width(185).Title((string)Resources.BCAResources.coxCompany); |
| columns.Add(o => o.cPhone).Title((string)Resources.BCAResources.stdPhone).Width(75); |
| columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100); |
| columns.Add(o => o.cEmail).Width(120).Title((string)Resources.BCAResources.stdEmail).Width(150); |
| columns.Add(o => o.cDateUpdated).Format("{0:MM/dd/yyyy}").Width(85).Title((string)Resources.BCAResources.stdUpdated); |
| columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdEdit, "Index", "Work", new { workindex = 2, OtherParms = "{0}" }, null).ToString()).Encoded(false).Title("").Width(32); |
| columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdDelete, "CompanyDelete", new { Id = "{0}" }, null).ToString()).Encoded(false).Title("").Width(50); |
| }) |
| .Ajax(settings => settings.Action("_AjaxBindingCompany", "Company")) |
| .Pageable() |
| .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn)) |
| .Scrollable(scrolling => scrolling.Height(253)) |
| .Filterable() %> |
| <p><%= Html.ActionLink((String)Resources.BCAResources.coxCreateNewCompany, "Index", "Work", new { workindex = 2, OtherParms = "Create" }, null)%></p> |
Thanks again for your help.
0
Hi IQworks,
I am not sure I understand what the problem is here. If it is that the column is encoded - use Encoded(false) for it.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I am not sure I understand what the problem is here. If it is that the column is encoded - use Encoded(false) for it.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
IQworks
Top achievements
Rank 1
answered on 04 Mar 2010, 05:29 PM
I am not sure what Encoded will buy me here, but my intention in providing all of the examples and screen shots, is to show that I cannot seem to find a way to display the email column in such a way so that a user can click on the email and have their email software provide its standard SEND page where the user can enter the subject, etc and send an email.
I was told that you cannot use a column template with an ajax bound grid - this gives me the ")" error I have mentioned a few times. And, trying to use the FORMAT(HTML.MAILTO) parameter for the email column displays as I demonstrate in the attatchment I included in my last post.
So, the problem is how do I code my email column to get the desired result, or is it even possible ?
Please let me know anything else I might send, or try. Perhaps it is just something simple I am not doing ?
and as always, thanks for your time and help.
I was told that you cannot use a column template with an ajax bound grid - this gives me the ")" error I have mentioned a few times. And, trying to use the FORMAT(HTML.MAILTO) parameter for the email column displays as I demonstrate in the attatchment I included in my last post.
So, the problem is how do I code my email column to get the desired result, or is it even possible ?
Please let me know anything else I might send, or try. Perhaps it is just something simple I am not doing ?
and as always, thanks for your time and help.
0
Hello IQworks,
Your last screenshot shows that the right html has been generated for the column. You only need to call Encoded(false) after setting the format so it is output as it should -clickable link - instead of HTML.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Your last screenshot shows that the right html has been generated for the column. You only need to call Encoded(false) after setting the format so it is output as it should -clickable link - instead of HTML.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
IQworks
Top achievements
Rank 1
answered on 05 Mar 2010, 02:39 AM
Atanas, thank you - it works just like I need it to, here is the final code ....
columns.Add(o => o.cEmail).Format(Html.Mailto(
"{0}", "{0}")).Encoded(false);
the trick was the {0} {0}, and of course the Encoded(false) that you suggested.
0
William
Top achievements
Rank 1
answered on 06 Jul 2011, 06:41 PM
".Format(Html.Mailto("{0}", "{0}")).Encoded(false)" yields a "Cannot resolve symbol 'MailTo'." error in my mvc3 project. Does anyone know what the updated syntax should be or what I should be including, if anything to fix this error?
Thanks,
William
Thanks,
William