Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • I want a column that is set as a hyperlink to call a javascript function and pass values from the grid row. Where do I set the NavigateUrlFormatString to have access to the grid row values of the selected cell.

                                    Thanks,

                                    Mike Grant

                                Show all comments
                                • Hi Mike,

                                  I suggest that you take a look at the following example, which that describes how to use the HyperLink column for the GridView extension:

                                  How to use the HyperLink column for the GridView extension

                                  Please let us know whether or not this meets your requirements.

                                  Thanks,
                                  Marion

                                • Michael Grant 01.23.2012

                                  Thanks Marion-

                                  But here is my problem. I have a column (MonthValue) that I want the hyper link. No problem there. I want the hperlink to call a javascript function client side. No problem there. My problem is that I want to pass not only the value of the current cell (MonthValue - {0}) to the called javascript function but also the value of 2 other other columns (Month & Account). I can setup the call to the javascript function for the current field, but I can't figure out how to get access to the Month and Account columns for the current row.

                                  The referenced example does not get me there.

                                  Thanks,

                                  Mike

                                • Kate T (DevExpress Support) 01.23.2012

                                  Hello Mike:

                                  I assume that the most optimal solution for this task is a custom HypeLink in DataItemTemlateContainer of the MonthValue column:

                                  [C#]
                                  settings.Columns.Add(column => { column.Caption = "#"; column.SetDataItemTemplateContent(c => { Html.DevExpress().HyperLink( settings => { settings.Name = "hyperLink1"; settings.ClientSideEvents.Click = "function(s,e){MyFunction("+DataBinder.Eval(c.DataItem, "Month").ToString()+","+DataBinder.Eval(c.DataItem, "Account").ToString()+");}"; settings.Properties.Text = "MyText"; } ) .Render(); }); });

                                  Please let me know whether this solution helps.

                                  Thanks
                                  Kate.

                                • Michael Grant 01.23.2012

                                  Kate -

                                  I think this looks like the right direction, but I am having some syntax problems. I forgot to mention that I am using a helper class to setup the grid:

                                  PartialIndex:
                                  @Html.DevExpress().GridView(TwoYearHistoryGridViewHelper.TYHGridViewSettings(Model, "Partial")).Bind(Model.Lines).GetHtml()

                                  TwoYearHistoryGridViewHelper:
                                          public static GridViewSettings TYHGridViewSettings(TwoYearHistoryModel inModel, String inAction)
                                          {
                                              return GetTYHGridViewSettings(inModel, inAction);
                                          }

                                          static GridViewSettings GetTYHGridViewSettings(TwoYearHistoryModel Model, String inAction)
                                          {
                                              GridViewSettings grid = new GridViewSettings();
                                              grid.CallbackRouteValues = new { Area = "Drilldowns", Controller = "History", Action = "PartialIndex", CostCenter = Model.CostCenter.CostCenter};
                                              grid.Name = "TYHGrid";
                                              grid.KeyFieldName = "Id";

                                              grid.Columns.Add(col =>
                                              {
                                                  col.FieldName = "Month";
                                                  col.ColumnType = MVCxGridViewColumnType.HyperLink;
                                                  col.Width = 120;
                                                  col.Caption = "Description";
                                                  col.SetDataItemTemplateContent(c =>
                                                  {
                                                      Html.DevExpress().HyperLink(settings =>
                                                      {
                                                          settings.Name = "hyperLink1";
                                                          settings.ClientSideEvents.Click = "function(s,e){MyFunction(" + DataBinder.Eval(c.DataItem, "Month").ToString() + "," + DataBinder.Eval(c.DataItem, "Account").ToString() + ");}";
                                                          settings.Properties.Text = "MyText";
                                                      }).Render();

                                                  });
                                              });

                                  When I put in your code for the SetDataItemTemplateContent, I am getting "The name 'Html' does not exist in current context". CAn you help with the piece that I am missing?

                                  Thanks,

                                  Mike

                                • Kate T (DevExpress Support) 01.23.2012

                                  Hello Michael:

                                  My initial example isn't quite correct. Please pardon this error.
                                  I have attached a sample that illustrates the solution. Please check the "ID" column in the GridView PartialView.

                                  Thanks
                                  Kate.

                                • Michael Grant 01.30.2012

                                  Kate -

                                  I have modified your sample to illustrate what I am trying to do. I have the grid settings in a seperate class (GridViewHelper). I am having a problem with the syntax of the SetDataItemTemplateContent in GridViewHelper.cs. Can you point out what I am doing wrong?

                                  Thanks,

                                  Mike

                                • Kate T (DevExpress Support) 02.01.2012

                                  Hello Michael:

                                  I assume that you can generate a new column in the main View and pass in to the GridHelper as a parameter of the GetGridViewSettings() method.
                                  I have modified your example according to this suggestion and attached it.
                                  Please let me know whether this solution is acceptable.

                                  In addition, you can check the following discussion in our forum where we have solved a similar problem:

                                  http://community.devexpress.com/forums/t/107499.aspx

                                  Thanks
                                  Kate.

                                • Michael Grant 02.01.2012

                                  Kate -

                                  My project actually has multiple columns with links that are generated by a single method called once for each column:
                                     AddMonthColumn(Model, grid, 0, "Month01");
                                     AddMonthColumn(Model, grid, 1, "Month02");
                                     AddMonthColumn(Model, grid, 2, "Month03");
                                     ...

                                          private static void AddMonthColumn(TwoYearHistoryModel Model, GridViewSettings grid, int iMonth, string fieldName)
                                          {
                                              MVCxGridViewColumn Column = grid.Columns.Add(fieldName, Model.ColumnHeaders[iMonth].Header, MVCxGridViewColumnType.Default);
                                              Column.PropertiesEdit.DisplayFormatString = "n0";
                                              Column.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
                                              Column.HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                                              Column.HeaderStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
                                              Column.Width = 50;
                                            //This is where I want to setup the hyperlink that calls a javascript as in the example that we have been working on
                                          }

                                  Is there any way to do this?

                                  Thanks,

                                  Mike

                                • Michael Grant 02.02.2012

                                  Kate -

                                  I reworked my project to setup the columns in the main view and not use the helper class. I have everything functioning the way I want, but the hyperlink columns are not displayed as an underlined link and the cursor does not change when hovering the link. How do I set these 2 properties on the hyperlink columns?

                                  Thanks,

                                  Mike

                                You must  log in  or  register  to leave comments

                                1 Solution

                                0

                                Hello Michael:

                                Thank you for your response.
                                Basically, the HyperLink extention is not underlined if the NavigateUrl property is not defined. You can change its behavior as follows:

                                [C#]
                                Html.DevExpress().HyperLink(hsettings => { hsettings.Name = "hyperLink1" + c.KeyValue.ToString(); hsettings.Properties.ClientSideEvents.Click = "function(s,e){MyFunction(" + DataBinder.Eval(c.DataItem, "ID").ToString() + "," + DataBinder.Eval(c.DataItem, "Subject").ToString() + ");}"; hsettings.Properties.Text = "MyText"; hsettings.NavigateUrl = "javascript:void"; }).Render();

                                This modification solves the issue with the cursor. It is changed to "pointer" when you hover over the hyperlink, as expected.

                                Thanks
                                Kate.

                                • Adit Malik 09.06.2013

                                  Hi Kate,

                                  I am using the same logic to add a hyperlink in a column that calls a javascript method with value from different column as parameter.

                                  below is the code for adding the column
                                  settings.Columns.Add(column => { column.SetDataItemTemplateContent(c => { Html.DevExpress().HyperLink(hyperLinkSettings => { var id = DataBinder.Eval(c.DataItem, "Id");
                                  if (id == null) { id = string.Empty; }
                                  hyperLinkSettings.Properties.ClientSideEvents.Click = "function(s,e){gotolink(" + id + ");}"; hyperLinkSettings.Properties.Text = DataBinder.Eval(c.DataItem, "Message").ToString(); hyperLinkSettings.NavigateUrl = "javascript:void"; }).Render(); }); });

                                  However The Loading pop up does not go.

                                  The data model is simple,
                                  Iitem
                                  {
                                  int id;
                                  string Message;
                                  }

                                  webbrowser debugger shows error message in the following function in the devexpress js
                                  function _aspxGetAttribute(obj, attrName){ if(obj.getAttribute) return obj.getAttribute(attrName); else if(obj.getPropertyValue) return obj.getPropertyValue(attrName); return null;}

                                  obj is null and thus uncaught exception

                                  what am I missing?

                                  Best regards,
                                  Adit Malik

                                • Hello Adit.

                                  Usually, we avoid discussing multiple questions within the same thread because this makes it difficult to track the entire conversation. Therefore, I have moved your next question to a separate thread: Q379787. Please refer to this ticket for further discussion.

                                You must  log in  or  register  to leave comments

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners