Window Close Rebind Datasource is Stored Procedure

4 posts, 0 answers
  1. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 25 Mar 2011 Link to this post

    I have used RadWindow many times and have always been able to do a close and rebind. This time however things are a little different. To rebind the data to a radgrid I need to call a SQL stored procedure.

    I have all the Javascript and Ajax code set just like the online example. This usually works. The typical Ajax Request Handler looks like:

    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
        If e.Argument = "Rebind" Then
            rgd_ABIUser.MasterTableView.SortExpressions.Clear()
            rgd_ABIUser.MasterTableView.GroupByExpressions.Clear()
            rgd_ABIUser.Rebind()
        ElseIf e.Argument = "RebindAndNavigate" Then
            rgd_ABIUser.MasterTableView.SortExpressions.Clear()
            rgd_ABIUser.MasterTableView.GroupByExpressions.Clear()
            rgd_ABIUser.MasterTableView.CurrentPageIndex = rgd_ABIUser.MasterTableView.PageCount - 1
            rgd_ABIUser.Rebind()
        End If
    End Sub

    This works when the radgrid is bound to a SQLDataSource. However, I need to rebind the grid using:

    Private Function GetUser() As DataTable
        Dim DatabaseName As String = rcb_Database.SelectedValue
        Dim SC As String = rcb_Site.SelectedValue
        Dim connectionString = New SqlConnection("server=DO-IT-AB\MSSQLAB;database=AeriesAdmin;UID=XXXX;PWD=XXXX;")
        Dim command = New SqlCommand("aa_abi_users_by_site", connectionString)
        command.CommandType = CommandType.StoredProcedure
        command.Parameters.Add("@DBName", SqlDbType.VarChar).Value = DatabaseName
        command.Parameters.Add("@SC", SqlDbType.VarChar).Value = SC
        command.Connection.Open()
        Dim myDataAdapter As New SqlDataAdapter(command)
        Dim myDataSet As New DataSet
        Dim dtData As New DataTable
        myDataAdapter.Fill(myDataSet)
        Return myDataSet.Tables(0)
        command.Connection.Close()
    End Function

    I tried to modify the handler to call my function but this does not work:

    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
        If e.Argument = "Rebind" Then
            rgd_ABIUser.MasterTableView.SortExpressions.Clear()
            rgd_ABIUser.MasterTableView.GroupByExpressions.Clear()
            rgd_ABIUser.DataSource = GetUser()
            rgd_ABIUser.Rebind()
        ElseIf e.Argument = "RebindAndNavigate" Then
            rgd_ABIUser.MasterTableView.SortExpressions.Clear()
            rgd_ABIUser.MasterTableView.GroupByExpressions.Clear()
            rgd_ABIUser.MasterTableView.CurrentPageIndex = rgd_ABIUser.MasterTableView.PageCount - 1
            rgd_ABIUser.DataSource = GetUser()
            rgd_ABIUser.Rebind()
        End If
    End Sub

    Any help performing a RadWindow Close and Rebind.

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 Mar 2011 Link to this post

    Hello Allan,


    Have you set AjaxSettings properly to update the grid on closing the window?
    How can I rebind my grid after a modal radwindow closes?



    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 28 Mar 2011 Link to this post

    I believe so. Here is my full ASPX:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="user_lookup_username.aspx.vb" Inherits="_Default" %>
      
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head id="Head1" runat="server">
        <title>Aeries Global System Manager</title>
    <link rel="stylesheet" type="text/css" href="~/includes/ITC_Main.css" /> 
      
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                function refreshGrid(arg) {
                    if (!arg) {
                        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
                    }
                    else {
                        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");
                    }
                }
            </script>
            </telerik:RadCodeBlock>
      
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="header">
      
            <table cellpadding="0" cellspacing="0" style="width: 100%; height: 40px;">
                <tr>
                    <td style="width: 200px; vertical-align: middle; text-align: center;">
                        <img alt="" src="../../images/aalogo.gif" style="width: 169px; height: 35px" /></td>
                    <td style="text-align: center;">
      
      
      
                        <datelbl:ShowDate ID="ShowDate1" runat="server" />
                    </td>
                    <td style="width: 300px; text-align: center;">
      
      
      
                                            <table cellpadding="2" cellspacing="0" 
                              
                            style="width: 292px; height: 40px; background-image: url('../../images/headerinset.gif'); text-align: center;">
                            <tr>
                                <td style="font-weight: bold; font-size: small; font-family: Arial, Helvetica, sans-serif; color: #00B000; text-align: center;">
                                    Logged in as: 
                                    <asp:LoginName ID="LoginName1" runat="server" Font-Names="Arial" 
                                        Font-Size="Small" ForeColor="#597791" 
                                        meta:resourcekey="LoginName1Resource1" />
                                         
                                    <asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="login" 
                                        meta:resourcekey="LoginStatus1Resource1" />
                                </td>
                            </tr>
                        </table></td>
                    <td style="text-align: center; vertical-align: middle; width: 175px;">
                        <img alt="" src="../../images/aatusdlogo.gif" style="width: 152px; height: 36px" /></td>
                </tr>
            </table>
      
        </div>
            <div id="subheader">
      
        </div>
                <div>
            <table cellpadding="0" cellspacing="0" style="width: 100%">
                <tr>
                    <td style="width: 250px; background-image: url('../../images/menuback.gif'); background-color: #E6E6E6; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: #000000;" 
                        valign="top">
                        <telerik:RadPanelBar ID="rpb_AA_Menu" Runat="server" DataFieldID="DataFieldID" 
                            DataFieldParentID="DataFieldParentID" 
                            DataNavigateUrlField="DataNavigateUrlField" DataSourceID="sds_AA_Menu" 
                            DataTextField="DataTextField" DataValueField="DataTextField" Width="250px" 
                            PersistStateInCookie="True" Skin="Office2007">
                            <DataBindings>
                                <telerik:RadPanelItemBinding SelectedImageUrlField="ImageURL" 
                                    ExpandedImageUrlField="ImageURL" HoveredImageUrlField="ImageURL" 
                                    ImageUrlField="ImageURL" />
                                <telerik:RadPanelItemBinding ImageUrlField="ImageURL" />
                            </DataBindings>
                        </telerik:RadPanelBar>
                          
                    </td>
                    <td valign="top" 
                        style="background-color: #FFFFFF; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: #000000;">
                        <table cellpadding="0" cellspacing="0" style="width: 100%">
                            <tr>
                                <td style="padding: 10px">
         <h1>
                        ABI
                        User Manager - User Lookup by User Name</h1>
                                    <h2>
                                        Database</h2>
                                                <telerik:RadComboBox ID="rcb_Database" Runat="server" 
                                                    DataSourceID="sds_Database" DataTextField="DatabaseName" 
                                                    DataValueField="DatabaseName" AppendDataBoundItems="True">
                                                    <Items>
                                                        <telerik:RadComboBoxItem Value = "" Text="Select" />
                                                    </Items>                                            
                                                    </telerik:RadComboBox>
                                            <h2>
                                                User </h2>
                                    <table cellpadding="0" cellspacing="0" style="width: 100%">
                                        <tr>
                                            <td style="width: 154px">
                                                <asp:TextBox ID="tbx_User" runat="server"></asp:TextBox>
                                            </td>
                                            <td>
                                                <asp:Button ID="Button1" runat="server" Text="Button" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="width: 154px">
                                                 </td>
                                            <td>
                                                 </td>
                                        </tr>
                                    </table>
      
      
      
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" onajaxrequest="RadAjaxManager1_AjaxRequest">  
            <AjaxSettings>  
                <telerik:AjaxSetting AjaxControlID="rgd_ABIUser">  
                    <UpdatedControls>  
                        <telerik:AjaxUpdatedControl ControlID="rgd_ABIUser" />  
                    </UpdatedControls>  
                </telerik:AjaxSetting>  
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                    <UpdatedControls>  
                        <telerik:AjaxUpdatedControl ControlID="rgd_ABIUser" />  
                    </UpdatedControls>  
                </telerik:AjaxSetting>  
            </AjaxSettings>  
        </telerik:RadAjaxManager>  
      
    <telerik:RadGrid ID="rgd_ABIUser" runat="server"  GridLines="None" AutoGenerateColumns="False" 
                                        Width="700px" AllowAutomaticUpdates="True">
        <MasterTableView DataKeyNames="ID,SC" commanditemdisplay="Top">
            <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
            <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridBoundColumn DataField="SC" HeaderText="Site" 
                        SortExpression="SC" UniqueName="SC" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
      
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ID" HeaderText="User" 
                        SortExpression="ID" UniqueName="ID"  HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="175px">
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
      
    <ItemStyle Width="175px"></ItemStyle>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="PW" HeaderText="Password" 
                        SortExpression="PW" UniqueName="PW"  HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="175px">
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
      
    <ItemStyle Width="175px"></ItemStyle>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="SN" HeaderText="TCH#" 
                        SortExpression="SN" UniqueName="SN" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
      
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="TG" HeaderText="Group" 
                        SortExpression="TG" UniqueName="TG" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
      
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="TemplateColumn">
                        <ItemTemplate
                        <asp:Button ID="btn_ModifyPerms" runat="server" Text="Modify" onclick="btn_ModifyABIUser_Click" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
        </MasterTableView>
    </telerik:RadGrid>
      
      
       
                                    <p>
                                         </p>
                                    <p>
                                         </p>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
                <div id="footer">
      
        </div>
      
      
            <asp:SqlDataSource ID="sds_AA_Menu" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AeriesAdmin_ConnectionString %>" 
            SelectCommand="SELECT [DataFieldID], [DataFieldParentID], [DataTextField], [DataNavigateUrlField], [ImageURL], [UserLevel] FROM [AA_Menu] WHERE ([UserLevel] LIKE '%' + @UserLevel + '%')">
                <SelectParameters>
                    <asp:SessionParameter Name="UserLevel" SessionField="RoleName" Type="String" />
                </SelectParameters>
        </asp:SqlDataSource>
          
        <telerik:RadScriptManager ID="rsm_AeriesAdmin" Runat="server">
        </telerik:RadScriptManager>
        <telerik:RadFormDecorator ID="rfd_AeriesAdmin" Runat="server" Skin="WebBlue" />
          
      
        <asp:SqlDataSource ID="sds_Database" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AeriesAdmin_ConnectionString %>" 
            SelectCommand="SELECT DISTINCT [DatabaseName] FROM [vw_AA_Databases] ORDER BY [DatabaseName]"></asp:SqlDataSource>
      
      
        <br />
          
        </form>
          
        </body>
    </html>


    Here is my VB:

    Imports System.Data
    Imports System.Data.SqlClient
    Imports Telerik.Web.UI
    Imports System.CodeDom
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.Security.Roles
    Imports System.Web.Security.Membership
    Imports System.Security
    Imports System.Security.Principal.WindowsIdentity
    Partial Class _Default
        Inherits System.Web.UI.Page
      
      
        'Protected Sub RadPanelBar1_DataBound1(ByVal sender As Object, ByVal e As System.EventArgs) Handles rpb_AA_Menu.DataBound
        '    rpb_AA_Menu.Items(0).Expanded = True
        '    rpb_AA_Menu.Items(1).Expanded = True
        'End Sub
      
      
        'Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad
      
        '    Dim ActiveDirID As String = "ActiveDirID"
        '    Dim connectionString As String = DirectCast(ConfigurationManager.ConnectionStrings("AeriesAdmin_ConnectionString").ConnectionString, String)
        '    Dim queryString As String = "SELECT ActiveDirID, RoleName, FullName, UserName FROM vw_ADSI WHERE UserName = @UserName"
      
        '    Using myConnection As New SqlConnection(connectionString)
        '        Dim myCommand As New SqlCommand(queryString, myConnection)
        '        myConnection.Open()
        '        myCommand.Parameters.AddWithValue("@UserName", User.Identity.Name)
        '        Dim MyReader As SqlDataReader = myCommand.ExecuteReader
        '        MyReader.Read()
        '        Session("UserName") = MyReader("UserName")
        '        Session("ActiveDirID") = MyReader("ActiveDirID")
        '        Session("RoleName") = MyReader("RoleName")
        '        myConnection.Close()
        '    End Using
      
      
        ' End Sub
      
      
      
      
      
        Protected Sub rgd_ABIUser_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgd_ABIUser.ItemDataBound
            If TypeOf e.Item Is GridCommandItem Then
                Dim cmditm As GridCommandItem = DirectCast(e.Item, GridCommandItem)
                cmditm.FindControl("InitInsertButton").Visible = False
                cmditm.FindControl("AddNewRecordButton").Visible = False
                cmditm.FindControl("RefreshButton").Visible = True
                cmditm.FindControl("RebindGridButton").Visible = True
            End If
        End Sub
      
      
        Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
      
            rgd_ABIUser.DataSource = GetUser()
            rgd_ABIUser.DataBind()
      
        End Sub
      
        Private Function GetUser() As DataTable
      
            Dim DatabaseName As String = rcb_Database.SelectedValue
            Dim ID As String = tbx_User.Text
      
            Dim connectionString = New SqlConnection("server=DO-IT-AB\MSSQLAB;database=AeriesAdmin;UID=XXXX;PWD=XXXX;")
            Dim command = New SqlCommand("aa_abi_users_by_id", connectionString)
      
            command.CommandType = CommandType.StoredProcedure
      
            command.Parameters.Add("@DBName", SqlDbType.VarChar).Value = DatabaseName
            command.Parameters.Add("@ID", SqlDbType.VarChar).Value = ID
      
            command.Connection.Open()
      
            Dim myDataAdapter As New SqlDataAdapter(command)
            Dim myDataSet As New DataSet
            Dim dtData As New DataTable
            myDataAdapter.Fill(myDataSet)
            Return myDataSet.Tables(0)
      
            command.Connection.Close()
      
        End Function
      
        Protected Sub btn_ModifyABIUser_Click(sender As Object, e As System.EventArgs)
      
            Dim ID_item As GridDataItem = DirectCast(TryCast(sender, Button).NamingContainer, GridDataItem)
            Dim ID As String = ID_item.OwnerTableView.DataKeyValues(ID_item.ItemIndex)("ID")
            Session("ID") = ID
            Dim SC_item As GridDataItem = DirectCast(TryCast(sender, Button).NamingContainer, GridDataItem)
            Dim SC As String = SC_item.OwnerTableView.DataKeyValues(SC_item.ItemIndex)("SC")
            Session("Site") = SC
            Session("DataBase") = rcb_Database.SelectedValue
      
            Dim windowManager As New RadWindowManager()
            Dim RadWindow As New RadWindow()
            RadWindow.OnClientClose = "refreshGrid"
            RadWindow.NavigateUrl = "user_mod_modal.aspx"
            RadWindow.ID = "RadWindow1"
            RadWindow.VisibleOnPageLoad = True
            RadWindow.Height = 375
            RadWindow.Width = 550
            RadWindow.Modal = True
            windowManager.Windows.Add(RadWindow)
            Me.form1.Controls.Add(RadWindow)
        End Sub
      
        Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
            If e.Argument = "Rebind" Then
                rgd_ABIUser.MasterTableView.SortExpressions.Clear()
                rgd_ABIUser.MasterTableView.GroupByExpressions.Clear()
                rgd_ABIUser.DataSource = GetUser()
                rgd_ABIUser.Rebind()
            ElseIf e.Argument = "RebindAndNavigate" Then
                rgd_ABIUser.MasterTableView.SortExpressions.Clear()
                rgd_ABIUser.MasterTableView.GroupByExpressions.Clear()
                rgd_ABIUser.MasterTableView.CurrentPageIndex = rgd_ABIUser.MasterTableView.PageCount - 1
                rgd_ABIUser.DataSource = GetUser()
                rgd_ABIUser.Rebind()
            End If
        End Sub
      
      
    End Class

    Thank you.
  5. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 31 Mar 2011 Link to this post

    Hi Allan,

     I examined your code and it seems to be correct as to updating the grid with AJAX. Do you get any errors when you try to edit or only the change is not applied? Also, are you sure that the refrsehGrid javascript function is actually correctly called from the RadWindow dialog?

    If the problem persists, please make a sample fully runnable demo - do not use your real database but a fake programmatic datasource or Northwind and also include fully runnable code for the RadWindow dialog page. I assume that the problem will reproduce no matter you use a stored procedure or not but if it does not, share a sample stored procedure with your code as well. Once you provide a fully runnable code, we will built up a sample and debug it on our side and we will modify it in order to meet your requirements so that you will be then able to apply the same logic in your original application as well.

    Best wishes,
    Svetlina
    the Telerik team
Back to Top