I have a RadGrid with a Hyperlink column in an ASP.Net page with VB.net as the code-behind in a RadWindow.
When user clicks on hyperlink column in the RadGrid, it should open another RadWindow that loads an ASP.Net page with some of the data from the row the user clicked on. But the problem is that it does not work on every row. It only works on some of the rows. It needs to work on every row.
I have even tried just putting the alert function in OpenUpdateCancelOrderWindow javascript function to see if it is calling the javascript function when clicking on the hyperlink.
Based on the alert not always popping up, it appears that the hyperlink in each row is not always getting the event handler attached to it.
What is causing the problem? How to resolve this?
Is there a better way to do this?
Please help!
Here is my RadGrid:
---------------------------------------------------------------------------------------
<telerik:RadGrid ID="rgRYGRelOrders" runat="server" Height="416px" Width="947px" AutoGenerateColumns="False" AllowPaging="True" PageSize="100"
OnDataBinding="rgRYGRelOrders_DataBinding" OnPageIndexChanged="rgRYGRelOrders_PageIndexChanged" OnNeedDataSource="rgRYGRelOrders_NeedDataSource" ShowGroupPanel="True" ShowStatusBar="True">
<GroupingSettings CollapseAllTooltip="Collapse all groups" />
<ExportSettings IgnorePaging="true">
<Pdf AllowPrinting="False">
</Pdf>
<Excel FileExtension="xlsx" Format="Xlsx" />
</ExportSettings>
<ClientSettings>
<Selecting AllowRowSelect="true" />
<Scrolling AllowScroll="true" UseStaticHeaders="true" />
</ClientSettings>
<MasterTableView EnableViewState="true" EnableLinqGrouping="False" DataKeyNames="ORDERDATE,RSDC_PART_NO,MILL_PART_NO,PO_SUPPLIER_CODE,QUANTITY,DELIVERYDATE,COMMENTS,ORDSTAT,USER_ID" ClientDataKeyNames="ORDERDATE,RSDC_PART_NO,MILL_PART_NO,PO_SUPPLIER_CODE,QUANTITY,DELIVERYDATE,COMMENTS,ORDSTAT,USER_ID">
<Columns>
<telerik:GridBoundColumn DataField="ORDERDATE" FilterControlAltText="Filter column0 column" HeaderText="Date/Time" ReadOnly="True" UniqueName="OrderDateTime">
<HeaderStyle Width="150px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="RSDC_PART_NO" FilterControlAltText="Filter column1 column" HeaderText="Part No." ReadOnly="True" UniqueName="RSDCPartNbr">
<HeaderStyle Width="160px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="QUANTITY" FilterControlAltText="Filter column2 column" HeaderText="Quantity" ReadOnly="True" UniqueName="Quantity" DataFormatString="{0:###,##0}">
<HeaderStyle Width="70px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DELIVERYDATE" FilterControlAltText="Filter column3 column" HeaderText="Requested Delivery Date" ReadOnly="True" UniqueName="DeliveryDate">
<HeaderStyle Width="150px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="COMMENTS" FilterControlAltText="Filter column4 column" HeaderText="Comments" ReadOnly="True" UniqueName="Comments">
<HeaderStyle Width="207px" />
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="TemplateUpdateOrderColumn">
<ItemTemplate>
<asp:HyperLink ID="UpdateOrderLink" runat="server" Text="Update Cancel Order"></asp:HyperLink>
</ItemTemplate>
<HeaderStyle Width="140px" />
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="ORDSTAT" FilterControlAltText="Filter column5 column" HeaderText="Status" ReadOnly="True" UniqueName="OrderStatus">
<HeaderStyle Width="120px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MILL_PART_NO" FilterControlAltText="Filter column6 column" HeaderText="Mill Part No." ReadOnly="True" UniqueName="MillPartNbr">
<HeaderStyle Width="160px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PO_SUPPLIER_CODE" FilterControlAltText="Filter column7 column" HeaderText="Supplier Code" ReadOnly="True" UniqueName="SuppCode">
<HeaderStyle Width="70px" />
</telerik:GridBoundColumn>
</Columns>
<GroupByExpressions>
<telerik:GridGroupByExpression>
<SelectFields>
<telerik:GridGroupByField FieldAlias="USER_ID" FieldName="USER_ID" FormatString="" HeaderText="Orders From" />
</SelectFields>
<GroupByFields>
<telerik:GridGroupByField FieldAlias="USER_ID" FieldName="USER_ID" FormatString="" HeaderText="" />
</GroupByFields>
</telerik:GridGroupByExpression>
</GroupByExpressions>
</MasterTableView>
<PagerStyle Mode="NextPrevNumericAndAdvanced" PageButtonCount="5" />
</telerik:RadGrid>
Here is some procedures for code-behind:
---------------------------------------------------------------------------------------
Protected Sub rgRYGRelOrders_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles rgRYGRelOrders.NeedDataSource
Try
Dim dtCurDate As DateTime = DateTime.Now
Dim strCurDate As String = dtCurDate.ToString("MM/dd/yyyy")
If (Session("RYGREPRELHISTSQLSTRING") Is Nothing) Then
sql = "SELECT USER_ID, TO_CHAR(ORDERDT,'MM/DD/YYYY HH12:MI:SS AM') AS ORDERDATE, RSDC_PART_NO, MILL_PART_NO, PO_SUPPLIER_CODE, QUANTITY, TO_CHAR(DELIVERY_DATE,'MM/DD/YYYY') AS DELIVERYDATE, COMMENTS, CASE WHEN CS_NOTIFIED = '0' AND CS_ORDERED = '0' THEN 'Waiting At RSDC' WHEN CS_NOTIFIED = 'X' AND CS_ORDERED = '0' THEN 'Notified' WHEN CS_NOTIFIED = 'X' AND CS_ORDERED = 'X' THEN 'Ordered' WHEN CS_ORDERED = 'R' THEN 'Rejected' WHEN CS_ORDERED = 'C' THEN 'Canceled' END AS ORDSTAT FROM ADMIN.RFI_DOH_ORDERS WHERE (ORDERDT >= TO_DATE('" & strCurDate & " 00:00:00', 'MM/DD/YYYY hh24:mi:ss' ) AND ORDERDT <= TO_DATE('" & strCurDate & " 23:59:59', 'MM/DD/YYYY hh24:mi:ss' )) ORDER BY ORDERDT ASC"
Session("RYGREPRELHISTSQLSTRING") = sql
Session("RYGREPRELHISTSTARTDATE") = dtCurDate
Session("RYGREPRELHISTENDDATE") = dtCurDate
Session("RYGREPRELHISTSORTBY") = "Ordered Date/Time"
Else
sql = CType(Session("RYGREPRELHISTSQLSTRING"), String)
End If
myDSData = DataSetConfiguration.OracleDataSet(sql, "S01")
'myDSData = DataSetConfiguration.OracleDataSet(sql, "RSDCBAK")
rgRYGRelOrders.DataSource = myDSData
Catch ex As Exception
strErrorMsg = "Procedure: rgRYGRelOrders_NeedDataSource - RYGReportViewTodaysReleases" & vbCrLf & "Error Message: " & ex.Message & vbCrLf & "Source: " & ex.Source
UserFunctions.UserMsgBox(Me, strErrorMsg)
End Try
End Sub
Protected Sub rgRYGRelOrders_ItemCreated(sender As Object, e As GridItemEventArgs) Handles rgRYGRelOrders.ItemCreated
Try
If TypeOf e.Item Is GridDataItem Then
Dim updateorderLink As HyperLink = DirectCast(e.Item.FindControl("UpdateOrderLink"), HyperLink)
updateorderLink.Attributes("href") = "javascript:void(0);"
'DataKeyValues is actually the name of the Data field name from the table, not the Unique Name for the column.
updateorderLink.Attributes("onclick") = [String].Format("return OpenUpdateCancelOrderWindow('{0}','{1}','{2}','{3}',{4},'{5}','{6}','{7}','{8}','{9}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ORDERDATE"), e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("RSDC_PART_NO"), e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("MILL_PART_NO"), e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("PO_SUPPLIER_CODE"), e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("QUANTITY"), e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("DELIVERYDATE"), e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("COMMENTS"), e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ORDSTAT"), e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("USER_ID"), "UpdateOrderLink")
End If
Catch ex As Exception
strErrorMsg = "Procedure: rgRYGRelOrders_ItemCreated - RYGReportViewTodaysReleases" & vbCrLf & "Error Message: " & ex.Message & vbCrLf & "Source: " & ex.Source
UserFunctions.UserMsgBox(Me, strErrorMsg)
End Try
End Sub
Protected Sub rgRYGRelOrders_DataBinding(sender As Object, e As EventArgs) Handles rgRYGRelOrders.DataBinding
Try
If Not IsPostBack Then
rgRYGRelOrders.CurrentPageIndex = SavedPageIndex
End If
Catch ex As Exception
strErrorMsg = "Procedure: rgRYGRelOrders_DataBinding - RYGReportViewTodaysReleases" & vbCrLf & "Error Message: " & ex.Message & vbCrLf & "Source: " & ex.Source
UserFunctions.UserMsgBox(Me, strErrorMsg)
End Try
End Sub
Protected Sub rgRYGRelOrders_PageIndexChanged(sender As Object, e As GridPageChangedEventArgs) Handles rgRYGRelOrders.PageIndexChanged
Try
SavedPageIndex = e.NewPageIndex
Catch ex As Exception
strErrorMsg = "Procedure: rgRYGRelOrders_PageIndexChanged - RYGReportViewTodaysReleases" & vbCrLf & "Error Message: " & ex.Message & vbCrLf & "Source: " & ex.Source
UserFunctions.UserMsgBox(Me, strErrorMsg)
End Try
End Sub
Here are Javascript functions in the ASP.net page:
---------------------------------------------------------------------------------------
<script type = "text/javascript" >
// Note: the following 2 examples require
// the GetRadWindow() function to exist on the page.
// It is needed to get a reference to the RadWindow wrapper
function GetRadWindow() {
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
return oWindow;
}
// CallFnOnParent shows how to call a function
// in the parent page.
function CallFnOnParent(sender) {
var btnID = sender.get_id();
GetRadWindow().BrowserWindow.openChildDialogNoTabStrip(btnID.toUpperCase());
// Tip: you can pass an argument to provide data to the called function
}
function OpenUpdateCancelOrderWindow(value1, value2, value3, value4, value5, value6, value7, value8,value9,value10) {
//alert('OpenUpdateCancelOrderWindow');
GetRadWindow().BrowserWindow.openChildDialogFromRadGrid(value1, value2, value3, value4, value5, value6, value7, value8, value9, value10);
// Tip: you can pass an argument to provide data to the called function
}
function OpenUpdateCancelOrderWindow2(value1) {
alert('OpenUpdateCancelOrderWindow2 --- Order Date='+value1);
//GetRadWindow().BrowserWindow.openChildDialogFromRadGrid(value1, value2, value3, value4, value5, value6, value7, value8, value9, value10);
// Tip: you can pass an argument to provide data to the called function
}
function CloseModal() {
var oWnd = GetRadWindow();
if (oWnd) setTimeout(function () { oWnd.close(); }, 0);
}
</script>
Here is the openChildDialogFromRadGrid javascript function in scripts.js included in the browser ASP.net page
---------------------------------------------------------------------------------------
function openChildDialogFromRadGrid(value1,value2,value3,value4,value5,value6,value7,value8,value9,value10) {
var sLinkname = value10;
var url;
var currentWnd = GetRadWindow();
var browserWnd = window;
if (currentWnd)
browserWnd = currentWnd.BrowserWindow;
if (sLinkname.toUpperCase() === "UPDATEORDERLINK") {
url = "RYGReportUpdateReleaseOrder.aspx?ORDDATE=" + value1 + "&RSDCPARTNBR=" + value2 + "&MILLPARTNBR=" + value3 + "&SUPPCODE=" + value4 + "&QTY=" + value5 + "&DLVRYDATE=" + value6 + "&COMMENTS=" + value7 + "&ORDSTAT=" + value8 + "&USERID=" + value9;
}
setTimeout(function () {
var wnd = browserWnd.radopen(url);
wnd.__parentBackReference = window; //pass the current window object of the page that opens the dialog so it can be used later
//wnd.center();
wnd.moveTo(0, 25);
if (sSender === "UPDATEORDERLINK") {
wnd.set_title('Release Order - Part No: ' + value2);
}
}, 0);
}
--------------------------------------------------------------------
Sincerely,
Keith Jackson