I'm filling the grid client side, but I want to make one of the cells a URL link to another site/page. Everything I've tried has not worked its displayed the link as a string not a link to be followed. Is this possible?
Hello legalke,
Did you try the cell’s “TargetURL” property - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.1/CLR4.0/html/Infragistics4.WebUI.UltraWebGrid.v11.1~Infragistics.WebUI.UltraWebGrid.UltraGridCell~TargetURL.html ?
If not, test it and let me know if it is working in your scenario.
Alex here's the code I'm using:
<script type="text/javascript"> function QtyChg() {
var qty, price; var parms;
qty = 0; price = 0; parms = "";
qty = $get('<%=qty.ClientID%>').value; price = $get('<%=price.ClientID%>').value;
parms = ""; parms = '{"qty":"' + qty + '"}';
$.ajax({ type: "POST", url: "WebForm1.aspx/QtyMsg", data: parms, contentType: "application/json; charset=utf-8", datatype: "json", success: function(datatable) {
var qtyarr = $.parseJSON(datatable.d); var grid = igtbl_getGridById("<%=UltraWebGrid1.ClientID%>");
while (grid.Rows.length > 0) { grid.Rows.getRow(0).deleteRow(); }
$.each(qtyarr.QtyTable, function() { var gridrow = igtbl_addNew("<%=UltraWebGrid1.ClientID%>", 0); gridrow.getCell(0).setValue(this.QtyMsg); gridrow.getCell(1).setValue(this.QtyLine); });
} }); }</script>
What am I doing wrong, I tried to setTargetURL and still nothing
Alex E. any ideas???
Can you tell me from where you get “QtyMsg” and “QtyLine” and in what format are these variables returned?
Also what type of column you use and did you set “TargetUrl” property from Server-Side (“InitializeRow” event) or on Client-Side (http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.1/CLR4.0/html/WebGrid_cell_Object_CSOM.html)?
A runnable sample will be helpful too if you can create one and attach it to this thread.
Alex,
The code snippet I posted receives a serialized Datatable from a server side Page Method. That's where QtyMsg and QtyLine are coming from. I create a JSON and parse them out and put the values into an UltrawebGrid client side. That's working fine what I want to do is create a "link" from one of those variables that will pass me to another page. I tried to set the TargetURL property on the client side and nothing appeared in the cell.
Alex, here's the server side code for the above snippet:
Imports System.Web.Script.Serialization
Partial Public Class WebForm1 Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim confocus, jsfocus As String
confocus = qty.ClientID jsfocus = "window.setTimeout(""try{document.getElementById('" & confocus & "').focus();} catch(e){}"",1000);" ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "TabFocusKey", jsfocus, True)
qty.Attributes.Add("onchange", "BLOCKED SCRIPTQtyChg()") End Sub
<System.Web.Services.WebMethod()> _ Public Shared Function QtyMsg(ByVal qty As String) As String
Dim makejson As New JavaScriptSerializer Dim rows As New List(Of Dictionary(Of String, Object)) Dim row As Dictionary(Of String, Object) Dim dtrow As DataRow Dim dttab As New DataTable() Dim jsonstr As String
jsonstr = "" If IsNumeric(qty) Then Else qty = 0 End If
dttab.Columns.Add("QtyMsg", System.Type.GetType("System.String")) dttab.Columns.Add("QtyLine", System.Type.GetType("System.String"))
dtrow = dttab.NewRow
dtrow(0) = "Quantity Has Been Entered" dtrow(1) = "1"
dttab.Rows.Add(dtrow)
dtrow(0) = "Second Message" dtrow(1) = "2"
For Each dr As DataRow In dttab.Rows row = New Dictionary(Of String, Object)
For Each dc As DataColumn In dttab.Columns row.Add(dc.ColumnName, dr(dc)) Next
rows.Add(row) Next
jsonstr = "{""QtyTable"" : " & makejson.Serialize(rows) & "}" Return jsonstr
End Function
End Class
I have used the following code (on HTML button click):
function setValue() { var grid = igtbl_getGridById("UltraWebGrid1"); var cell = grid.Rows.getRow(1).getCell(2); cell.setTargetURL('http://ko.infragistics.com'); cell.setValue("Test"); }
function setValue() {
var grid = igtbl_getGridById("UltraWebGrid1");
var cell = grid.Rows.getRow(1).getCell(2);
cell.setTargetURL('http://ko.infragistics.com');
cell.setValue("Test");
}
With this code I have set a new hyperlink with value “Test” pointing to our site.
The important thing here is the type of the column it should be set of type Hyperlink or the code will not be applied correctly to grid cell:
<igtbl:UltraGridColumn HeaderText="" Key="Data" EditorControlID="" Hidden="False" Format="" BaseColumnName="Data" FooterText="" Width="50%" Type="HyperLink">
Test this approach and let me know if it is working in your application.
Thanks for all your help your last suggestion gave me exactly what I was looking for