Solved

RadGrid not rebinding after detailsview update event?

Posted on 2016-07-27
2
64 Views
Last Modified: 2016-07-29
Hello, I am trying to update records displayed in a RadGrid using a detailsview control.  The problem I am facing is that once the "Save" / update event happens, the RadGrid does not update unless I refresh the page, which I am trying to avoid.  Any guidance is most appreciated!

ss1
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h3>
        Edit Current
    </h3>
    <br/>
    <div>
        <%--<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel" LoadingPanelID="RadAjaxLoadingPanel1">--%>
        <%--<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxManager ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="SaveButton">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
        </telerik:AjaxSetting>
        </AjaxSettings>
        </telerik:RadAjaxManager>--%>
            <div class="datagrid">
                <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" DataSourceID="sqlds_Employee" AllowSorting="true" Skin="Default" >
                    <MasterTableView DataSourceID="sqlds_Employee" AutoGenerateColumns="False" DataKeyNames="TID,EmpID">
                        <Columns>
                            <telerik:GridBoundColumn DataField="EmpID" HeaderText="EmpID" SortExpression="EmpID" UniqueName="EmpID" Display="False">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="TID" HeaderText="TID" SortExpression="TID" UniqueName="TID" Display="True">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="FullName" HeaderText="Name" SortExpression="FullName" UniqueName="FullName" ItemStyle-Wrap="False">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="StmtDate" HeaderText="StmtDate" SortExpression="StmtDate" UniqueName="StmtDate" DataFormatString="{0:d}" ItemStyle-Wrap="False">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="TranDate" HeaderText="TranDate" SortExpression="TranDate" UniqueName="TranDate" DataFormatString="{0:d}" ItemStyle-Wrap="False">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PostDate" HeaderText="PostDate" SortExpression="PostDate" UniqueName="PostDate" DataFormatString="{0:d}" ItemStyle-Wrap="False">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Merchant" HeaderText="Merchant" SortExpression="Merchant" UniqueName="Merchant" ItemStyle-Wrap="False">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="TranAmt" HeaderText="TranAmt" SortExpression="TranAmt" UniqueName="TranAmt" DataFormatString="{0:C}" ItemStyle-Wrap="False" ItemStyle-HorizontalAlign="Right">
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn DataField="" HeaderText="" SortExpression="" UniqueName="imgStatus">
                                <ItemTemplate>
                                    <asp:Image ID="imgStatus" runat="server" />
                                </ItemTemplate>
                                <ItemStyle Wrap="False"/>
                            </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="LastSaved" HeaderText="LastSaved" SortExpression="LastSaved" UniqueName="LastSaved" DataFormatString="{0:g}" ItemStyle-Wrap="False" ItemStyle-HorizontalAlign="Left">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings EnablePostBackOnRowClick="true" Selecting-AllowRowSelect="true" EnableRowHoverStyle="True">
                        <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="300px"/>
                    </ClientSettings>
                </telerik:RadGrid>
            </div>
            <div class="recordDetail">
                <br/>
                <asp:Label ID="lblRecord" runat="server" Text="No record selected."></asp:Label>
                &nbsp;
                <asp:Button id="SaveButton" text="Save" Width="60px" runat="server" CommandName="Update" />
                &nbsp;
                <asp:button id="CancelButton" text="Cancel" runat="server" CausesValidation="False" OnClick="CancelButton_Click"/>
                <br/><br/>
            </div>

        <div class="formview">
        <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="sqlds_SelectedRec" AutoGenerateRows="False"
                     DefaultMode="Edit" DataKeyNames="TID" BorderStyle="None" Width="500px" CellPadding="3" GridLines="None" CellSpacing="2" 
                     InsertRowStyle-Wrap="False" RowStyle-Wrap="False">
        <FieldHeaderStyle Wrap="False" HorizontalAlign="Left" />
        <Fields>
            <asp:TemplateField HeaderText="Department" HeaderStyle-CssClass="bold">
                <EditItemTemplate>
                     <asp:DropDownList ID="ddDept" runat="server" AutoPostBack="True" DataSourceID="sqlds_DDDept" DataTextField="DESCRIPTION"
                                       DataValueField="ENTRYID" AppendDataBoundItems="True" OnSelectedIndexChanged="ddDept_SelectedIndexChanged" OnDataBound="ddDept_OnDataBound">
                        <asp:ListItem></asp:ListItem>
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="rfvDept" runat="server" ErrorMessage="REQUIRED" CssClass="RequiredField" ControlToValidate="ddDept"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Activity Number" HeaderStyle-CssClass="bold">
                <EditItemTemplate>
                    <asp:DropDownList ID="ddActivity" runat="server" AutoPostBack="False" DataSourceID="sqlds_DDActNum" DataTextField="DESCRIPTION"
                                      DataValueField="PROJECTID"  AppendDataBoundItems="True" OnDataBound="ddActivity_OnDataBound" >
                         <asp:ListItem Value="" Text="Selection required"></asp:ListItem>
                         <asp:ListItem Value="99" Text="Not applicable"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="rfvActivity" runat="server" ErrorMessage="REQUIRED" CssClass="RequiredField" ControlToValidate="ddActivity" Display="Dynamic"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Expense Type" HeaderStyle-CssClass="bold">
                <EditItemTemplate>
                    <asp:DropDownList ID="ddExpType" runat="server" AutoPostBack="false" DataSourceID="sqlds_DDExpType" DataTextField="Description"
                                      DataValueField="ExpID"  AppendDataBoundItems="True" OnDataBound="ddExpType_OnDataBound">
                        <asp:ListItem Value="" Text="Selection required"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="rfvExpType" runat="server" ErrorMessage="REQUIRED" CssClass="RequiredField" ControlToValidate="ddExpType" Display="Dynamic"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Business Purpose/Comments" HeaderStyle-CssClass="bold">
                <EditItemTemplate>
                        <asp:TextBox ID="txtBP" runat="server" Text='<%#bind("Purpose")%>' Wrap="False" Width="300" ValidationGroup="grpBP"></asp:TextBox>
                               <asp:CustomValidator id="cvBP"
                                   ControlToValidate="txtBP"
                                   Display="Static"
                                   ErrorMessage="REQUIRED"
                                   CssClass="RequiredField"
                                   OnServerValidate="ServerValidation1"
                                   ValidateEmptyText="True"
                                   runat="server"/>
                </EditItemTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Person(s) Entertained" HeaderStyle-CssClass="bold">
                <EditItemTemplate>
                   <asp:TextBox ID="txtPersEnt" runat="server" Text='<%#bind("EntertainWho")%>' Wrap="False" Width="300" ></asp:TextBox>
                                <asp:CustomValidator id="cvPE"
                                   ControlToValidate="txtPersEnt"
                                   Display="Static"
                                   ErrorMessage="REQUIRED"
                                   CssClass="RequiredField"
                                   OnServerValidate="ServerValidation1"
                                   ValidateEmptyText="True"
                                   runat="server"/>
                </EditItemTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Destination City" HeaderStyle-CssClass="bold">
                <EditItemTemplate>
                   <asp:TextBox ID="txtDestCity" runat="server" Text='<%#bind("TravelTo")%>' Wrap="False" Width="300"></asp:TextBox>
                                <asp:CustomValidator id="cvDestCity"
                                   ControlToValidate="txtDestCity"
                                   Display="Static"
                                   ErrorMessage="REQUIRED"
                                   CssClass="RequiredField"
                                   OnServerValidate="ServerValidation1"
                                   ValidateEmptyText="True"
                                   runat="server"/>
                </EditItemTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Third Party Info" HeaderStyle-CssClass="bold">
                <EditItemTemplate>
                     <asp:TextBox ID="txtPartyInfo" runat="server" Text='<%#bind("ThirdPartyInfo")%>' Wrap="False" Width="300"></asp:TextBox>
                                   <asp:CustomValidator id="cvPartyInfo"
                                   ControlToValidate="txtPartyInfo"
                                   Display="Static"
                                   ErrorMessage="REQUIRED"
                                   CssClass="RequiredField"
                                   OnServerValidate="ServerValidation1"
                                   ValidateEmptyText="True"
                                   runat="server"/>
                </EditItemTemplate>
            </asp:TemplateField>

<%--            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:Button ID="Button1" runat="server" CausesValidation="True" CommandName="Update" Text="Save" />
                </EditItemTemplate>
                <ItemStyle HorizontalAlign="Left" />
            </asp:TemplateField>--%>
        </Fields>
    </asp:DetailsView>
        </div>
    </div>
    <br/>
    
    
    <asp:SqlDataSource ID="sqlds_Employee" runat="server" ConnectionString="<%$ ConnectionStrings:DirectoryConnectionString %>"
                       SelectCommand="SELECT e.EmpID, e.LName + ', ' + e.FName AS FullName, c.*, t.* FROM [Directory].[dbo].[_Employees] e 
                                            JOIN [CorpCard_new].[dbo].[CHolders] c ON e.EmpID = c.EmpID 
                                            JOIN [CorpCard_new].[dbo].[Trans] t ON t.AcctNum = c.CardNumber AND LogID IS NULL
                                            WHERE e.UserName = @UserName">
                       <selectparameters>
                           <asp:sessionparameter name="UserName" sessionfield="strLoginName" type="String" />
	                   </selectparameters>
    </asp:SqlDataSource>
    
    <asp:SqlDataSource ID="sqlds_SelectedRec" runat="server" ConnectionString="<%$ ConnectionStrings:CorpCardConnectionString %>"
                       SelectCommand="SELECT * FROM [Trans] WHERE AcctNum=@CardNum AND LogID IS NULL"
                       UpdateCommand="UPDATE [Trans] SET ExpID = 0 WHERE TID = 0">
                       <selectparameters>
                           <asp:sessionparameter name="CardNum" sessionfield="CardNum" type="String" />
	                   </selectparameters>
                       <updateparameters>
		                   <asp:parameter name="TID" type="String" />
                           <asp:parameter name="ENTRYID" type="String" />
		                   <asp:parameter name="ActivityCode" type="String" />
                           <asp:parameter name="ExpID" type="String" />
                           <asp:parameter name="Purpose" type="String" />
                           <asp:parameter name="EntertainWho" type="String" />
                           <asp:parameter name="TravelTo" type="String" />
                           <asp:parameter name="ThirdPartyInfo" type="String" />
                           <asp:parameter name="LastSaved" type="String" />
	                   </updateparameters>
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="sqlds_DDDept" runat="server" ConnectionString="<%$ ConnectionStrings:FE_ProdConnectionString %>"
                       SelectCommand="SELECT * FROM TABLEENTRIES WHERE CODETABLESID = 1023 AND Active <> 0 ORDER BY Description">
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="sqlds_DDExpType" runat="server" ConnectionString="<%$ ConnectionStrings:CorpCardConnectionString %>"
                       SelectCommand="SELECT ExpID, ExpenseDesc + ' - ' + ExpenseNum AS Description FROM ExpType WHERE IsActive = 1 ORDER BY ExpenseDesc">
    </asp:SqlDataSource>
    
    <asp:SqlDataSource ID="sqlds_DDActNum" runat="server" ConnectionString="<%$ ConnectionStrings:FE_ProdConnectionString %>"
                       SelectCommand="">
    </asp:SqlDataSource>

</asp:Content>

Open in new window


    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        
        'RadScriptManager.GetCurrent(Page).RegisterPostBackControl(SaveButton)

        Session.Remove("intDeptID")
        Session.Remove("strLoginName")
        Session.Remove("intEmpID")
        Session.Remove("intAcctID")
        Session.Remove("sLabName")

        'capture login info
        Dim Parts As String() = HttpContext.Current.User.Identity.Name.Split("\")
        If Parts.Length = 2 Then
            Session("strLoginName") = Parts(1)
        Else
            Session("strLoginName") = HttpContext.Current.User.Identity.Name
        End If

        'for debugging
        Session("strLoginName") = "ahelbling"

        Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("DirectoryConnectionString").ConnectionString)
            stCon.Open()
            Dim selCommand As New SqlCommand("SELECT DeptID FROM _Employees WHERE UserName=@UID AND isActive = 1", stCon)
            selCommand.Parameters.Add("@UID", SqlDbType.NVarChar).Value = Session("strLoginName")
            Dim intDeptID As Integer = CType(selCommand.ExecuteScalar, Integer)
            Session("intDeptID") = intDeptID

            Dim selCommand2 As New SqlCommand("SELECT EmpID FROM _Employees WHERE UserName=@UID AND isActive = 1", stCon)
            selCommand2.Parameters.Add("@UID", SqlDbType.NVarChar).Value = Session("strLoginName")
            intEmpID = CType(selCommand2.ExecuteScalar, Integer)
            Session("intEmpID") = intEmpID

            Dim selCommand3 As New SqlCommand("SELECT LawsonDept FROM _Employees WHERE UserName=@UID AND isActive = 1", stCon)
            selCommand3.Parameters.Add("@UID", SqlDbType.NVarChar).Value = Session("strLoginName")
            Dim intAcctID As Integer = CType(selCommand3.ExecuteScalar, Integer)
            Session("intAcctID") = intAcctID
        End Using
        
        sLabID = CType(Session("intDeptID"), String)
        sAcctID = CType(Session("intAcctID"), String)
        sEmpID = CType(Session("intEmpID"), String)
        sUserName = CType(Session("strLoginName"), String)
        
        If Not Page.IsPostBack Then

           Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("DirectoryConnectionString").ConnectionString)
            stCon.Open()

                Dim selCommand4 As New SqlCommand("SELECT CardNumber FROM [CorpCard_new].[dbo].[CHolders] WHERE EmpID=1013", stCon)
                selCommand4.Parameters.Add("@UID", SqlDbType.Int).Value = 1013
                Dim sCardNum As String = CType(selCommand4.ExecuteScalar, String)
                Session("CardNum") = sCardNum
               
            End Using

            sqlds_DDActNum.SelectCommand =
                "SELECT a.PROJECTID, a.DESCRIPTION + ' - ' + a.PROJECTID AS DESCRIPTION FROM GL7PROJECTS a, GL7PROJECTATTRIBUTES b, TABLEENTRIES c WHERE c.ENTRYID = '" +
                sAcctID + "' AND c.CODETABLESID = 1023 AND c.TABLEENTRIESID = b.TABLEENTRIESID and b.PARENTID = a.GL7PROJECTSID AND a.ACTIVEFLAG = 1 ORDER BY ENTRYID"
           
            SaveButton.Visible = False
            CancelButton.Visible = False
            SaveButton.Enabled = False
            CancelButton.Enabled = False

        End If

    End Sub

    
    Protected Sub RadGrid1_DataBound(sender As Object, e As EventArgs) Handles RadGrid1.DataBound

        If RadGrid1.MasterTableView.Items.Count > 0 Then
	        RadGrid1.MasterTableView.Items(0).Selected = True

            Dim item As GridDataItem = DirectCast(RadGrid1.SelectedItems(0), GridDataItem)
	        TID = CType(item("TID").Text, Integer)
            Dim Merchant As String = item("Merchant").Text
            Dim Amt As String = item("TranAmt").Text
            Dim sLastSaved As String = item("LastSaved").Text
	    
            sqlds_SelectedRec.SelectCommand = "SELECT * FROM [CorpCard_new].[dbo].[Trans] WHERE TID = " & TID
        
            lblRecord.Text = TID.ToString() + " - " + Merchant + " - " + Amt
            SaveButton.Visible = True
            CancelButton.Visible = True
            SaveButton.Enabled = True
            CancelButton.Enabled = True
            'DetailsView1.Databind()
        End If

    End Sub


    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemDataBound

         If TypeOf e.Item Is GridDataItem Then
            
            Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
	        TID = item.GetDataKeyValue("TID").ToString()
            
            Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("DirectoryConnectionString").ConnectionString)
                stCon.Open()

                Dim imgStatus As Image = TryCast(item.FindControl("imgStatus"), Image)
                Dim selCommand As New SqlCommand("SELECT ExpID FROM [CorpCard_new].[dbo].[Trans] WHERE TID=@TID", stCon)
                selCommand.Parameters.Add("@TID", SqlDbType.Int).Value = TID
                Dim sExpID As String = CType(selCommand.ExecuteScalar, String)
                If sExpID = "0" Then
                    imgStatus.ImageUrl = "images/incomplete-symbol-25.png"
                Else
                    imgStatus.ImageUrl = "images/Verified.png"
                End If
            End Using

        End If

    End Sub
    

    Protected Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource

        sUserName = CType(Session("strLoginName"), String)
        sqlds_Employee.SelectCommand = "SELECT e.EmpID, e.LName + ', ' + e.FName AS FullName, c.*, t.* FROM [Directory].[dbo].[_Employees] e " & _
                                            "JOIN [CorpCard_new].[dbo].[CHolders] c ON e.EmpID = c.EmpID " & _
                                            "JOIN [CorpCard_new].[dbo].[Trans] t ON t.AcctNum = c.CardNumber AND LogID IS NULL " & _
                                            "WHERE e.UserName = @UserName"
        sqlds_Employee.SelectParameters.Add("UserName", Data.DbType.String, sUserName)
        RadGrid1.Rebind()

    End Sub
    

    Protected Sub RadGrid1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RadGrid1.SelectedIndexChanged
        
        Dim item As GridDataItem = DirectCast(RadGrid1.SelectedItems(0), GridDataItem)
	    TID = CType(item("TID").Text, Integer)
        Dim Merchant As String = item("Merchant").Text
        Dim Amt As String = item("TranAmt").Text
        Dim sLastSaved As String = item("LastSaved").Text
	    
        sqlds_SelectedRec.SelectCommand = "SELECT * FROM [CorpCard_new].[dbo].[Trans] WHERE TID = " & TID
        
        lblRecord.Text = TID.ToString() + " - " + Merchant + " - " + Amt
        SaveButton.Visible = True
        CancelButton.Visible = True
        SaveButton.Enabled = True
        CancelButton.Enabled = True
        'DetailsView1.Databind()
        'RadGrid1.Rebind()
        
    End Sub
    


    Protected Sub DetailsView1_DataBound(sender As Object, e As EventArgs) Handles DetailsView1.DataBound
        
        Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("DirectoryConnectionString").ConnectionString)
            stCon.Open()
            
            Dim ddDept As DropDownList = DirectCast(DetailsView1.FindControl("ddDept"), DropDownList)
            sLabID = CType(Session("intAcctID"), String)
            Dim selCommand4 As New SqlCommand("SELECT ACCT_UNIT FROM [CorpCard_new].[dbo].[Trans] WHERE TID=@TID", stCon)
            selCommand4.Parameters.Add("@TID", SqlDbType.Int).Value = TID
            Dim sAcctUnit As String = CType(selCommand4.ExecuteScalar, String)
            If sAcctUnit = "0" Then
                ddDept.SelectedValue = sLabID
            Else
                ddDept.SelectedValue = sAcctUnit
            End If
            sDeptID = ddDept.SelectedValue
        
            Dim ddActNum As DropDownList = DirectCast(DetailsView1.FindControl("ddActivity"), DropDownList)
            sqlds_DDActNum.SelectCommand =
                "SELECT a.PROJECTID, a.DESCRIPTION + ' - ' + a.PROJECTID AS DESCRIPTION FROM GL7PROJECTS a, GL7PROJECTATTRIBUTES b, TABLEENTRIES c WHERE c.ENTRYID = '" +
                sDeptID + "' AND c.CODETABLESID = 1023 AND c.TABLEENTRIESID = b.TABLEENTRIESID and b.PARENTID = a.GL7PROJECTSID AND a.ACTIVEFLAG = 1 ORDER BY ENTRYID"
            'ddActNum.Items.Clear()
            Dim selCommand5 As New SqlCommand("SELECT ActivityNum FROM [CorpCard_new].[dbo].[Trans] WHERE TID=@TID", stCon)
            selCommand5.Parameters.Add("@TID", SqlDbType.Int).Value = TID
            Dim sActNum As String = CType(selCommand5.ExecuteScalar, String)
            If sActNum = "99" Then
                ddActNum.SelectedValue = Nothing
            Else
                ddActNum.SelectedValue = sActNum
            End If
            
            Dim ddExpType As DropDownList = DirectCast(DetailsView1.FindControl("ddExpType"), DropDownList)
            Dim selCommand6 As New SqlCommand("SELECT ExpID FROM [CorpCard_new].[dbo].[Trans] WHERE TID=@TID", stCon)
            selCommand6.Parameters.Add("@TID", SqlDbType.Int).Value = TID
            Dim sExpType As String = CType(selCommand6.ExecuteScalar, String)
            If sExpType = "0" Then
                ddExpType.SelectedValue = Nothing
            Else
                ddExpType.SelectedValue = sExpType
            End If

            Dim txtPurpose As TextBox = DirectCast(DetailsView1.FindControl("txtBP"), TextBox)
            Dim selCommand8 As New SqlCommand("SELECT Purpose FROM [CorpCard_new].[dbo].[Trans] WHERE TID=@TID", stCon)
            selCommand8.Parameters.Add("@TID", SqlDbType.Int).Value = TID
            Dim temp1 As Object = selCommand8.ExecuteScalar
            IF NOT IsDBNull(temp1) Then
                Dim sPurpose As String = CType(temp1, String)
                txtPurpose.Text = sPurpose
            Else
                txtPurpose.Text = ""
            End If

            Dim txtEntertain As TextBox = DirectCast(DetailsView1.FindControl("txtPersEnt"), TextBox)
            Dim selCommand9 As New SqlCommand("SELECT EntertainWho FROM [CorpCard_new].[dbo].[Trans] WHERE TID=@TID", stCon)
            selCommand9.Parameters.Add("@TID", SqlDbType.Int).Value = TID
            Dim temp2 As Object = selCommand9.ExecuteScalar
            IF NOT IsDBNull(temp2) Then
                Dim sEntertain As String = CType(temp2, String)
                txtEntertain.Text = sEntertain
            Else
                txtEntertain.Text = ""
            End If

            Dim txtDestCity As TextBox = DirectCast(DetailsView1.FindControl("txtDestCity"), TextBox)
            Dim selCommand10 As New SqlCommand("SELECT TravelTo FROM [CorpCard_new].[dbo].[Trans] WHERE TID=@TID", stCon)
            selCommand10.Parameters.Add("@TID", SqlDbType.Int).Value = TID
            Dim temp3 As Object = selCommand10.ExecuteScalar
            IF NOT IsDBNull(temp3) Then
                Dim sDestCity As String = CType(temp3, String)
                txtDestCity.Text = sDestCity
            Else
                txtDestCity.Text = ""
            End If

            Dim txtThirdParty As TextBox = DirectCast(DetailsView1.FindControl("txtPartyInfo"), TextBox)
            Dim selCommand11 As New SqlCommand("SELECT ThirdPartyInfo FROM [CorpCard_new].[dbo].[Trans] WHERE TID=@TID", stCon)
            selCommand11.Parameters.Add("@TID", SqlDbType.Int).Value = TID
            Dim temp4 As Object = selCommand11.ExecuteScalar
            IF NOT IsDBNull(temp4) Then
                Dim sThirdParty As String = CType(temp4, String)
                txtThirdParty.Text = sThirdParty
            Else
                txtThirdParty.Text = ""
            End If
            
        End Using      
        
    End Sub


    Protected Sub DetailsView1_ItemUpdated(sender As Object, e As DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
        
        Dim item As GridDataItem = DirectCast(RadGrid1.SelectedItems(0), GridDataItem)
	    TID = CType(item("TID").Text, Integer)
        Dim Merchant As String = item("Merchant").Text
        Dim Amt As String = item("TranAmt").Text
        Dim sLastSaved As String = item("LastSaved").Text
	    
        sqlds_SelectedRec.SelectCommand = "SELECT * FROM [CorpCard_new].[dbo].[Trans] WHERE TID = " & TID
        
        lblRecord.Text = TID.ToString() + " - " + Merchant + " - " + Amt
        SaveButton.Visible = True
        CancelButton.Visible = True
        SaveButton.Enabled = True
        CancelButton.Enabled = True
        DetailsView1.Databind()
        'RadGrid1.DataSourceID = vbNull
        'RadGrid1.DataBind()

    End Sub


    Protected Sub ddDept_OnDataBound(sender As Object, e As EventArgs)
        
        ' Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("DirectoryConnectionString").ConnectionString)
        '    stCon.Open()
        '    Dim selCommand4 As New SqlCommand("SELECT ACCT_UNIT FROM [CorpCard_new].[dbo].[Trans] WHERE TID=@TID", stCon)
        '    selCommand4.Parameters.Add("@TID", SqlDbType.Int).Value = TID
        '    Dim sAcctUnit As String = CType(selCommand4.ExecuteScalar, String)
        '    If sAcctUnit = 0 Then
        '        Dim ddDept As DropDownList = DirectCast(DetailsView1.FindControl("ddDept"), DropDownList)
        '        sDeptID = ddDept.SelectedValue
        '    Else
        '        Dim ddDept As DropDownList = DirectCast(DetailsView1.FindControl("ddDept"), DropDownList)
        '        ddDept.SelectedValue = sAcctUnit
        '    End If

        'End Using


        'Dim ddActNum As DropDownList = DirectCast(DetailsView1.FindControl("ddActivity"), DropDownList)
        'ddActNum.Items.Clear()

        'Dim ddDept As DropDownList = DirectCast(DetailsView1.FindControl("ddDept"), DropDownList)
        'sDeptID = ddDept.SelectedValue
        
        'sqlds_DDActNum.SelectCommand =
        '    "SELECT a.PROJECTID, a.DESCRIPTION + ' - ' + a.PROJECTID AS DESCRIPTION FROM GL7PROJECTS a, GL7PROJECTATTRIBUTES b, TABLEENTRIES c WHERE c.ENTRYID = '" +
        '    sDeptID + "' AND c.CODETABLESID = 1023 AND c.TABLEENTRIESID = b.TABLEENTRIESID and b.PARENTID = a.GL7PROJECTSID AND a.ACTIVEFLAG = 1 ORDER BY ENTRYID"
        '    ddActNum.Items.Insert(0, New ListItem("Selection required", ""))
        '    ddActNum.Items.Insert(1, New ListItem("Not applicable", "99"))
        '    'ddActNum.SelectedIndex = 0

    End Sub
    

    Protected Sub ddDept_SelectedIndexChanged(sender As Object, e As EventArgs)
        
        Dim ddActNum As DropDownList = DirectCast(DetailsView1.FindControl("ddActivity"), DropDownList)
        ddActNum.Items.Clear()

        Dim ddDept As DropDownList = DirectCast(DetailsView1.FindControl("ddDept"), DropDownList)
        sDeptID = ddDept.SelectedValue
        
        sqlds_DDActNum.SelectCommand =
            "SELECT a.PROJECTID, a.DESCRIPTION + ' - ' + a.PROJECTID AS DESCRIPTION FROM GL7PROJECTS a, GL7PROJECTATTRIBUTES b, TABLEENTRIES c WHERE c.ENTRYID = '" +
            sDeptID + "' AND c.CODETABLESID = 1023 AND c.TABLEENTRIESID = b.TABLEENTRIESID and b.PARENTID = a.GL7PROJECTSID AND a.ACTIVEFLAG = 1 ORDER BY ENTRYID"
            ddActNum.Items.Insert(0, New ListItem("Selection required", ""))
            ddActNum.Items.Insert(1, New ListItem("Not applicable", "99"))
            'ddActNum.SelectedIndex = 0

    End Sub
    

    Protected Sub ddActivity_OnDataBound(sender As Object, e As EventArgs)
    
    

    End Sub


    Protected Sub ddExpType_OnDataBound(sender As Object, e As EventArgs)
        
        'Dim ddExpType As DropDownList = DirectCast(DetailsView1.FindControl("ddExpType"), DropDownList)
        'ddExpType.SelectedIndex = -1

    End Sub
    

    
    Protected Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
        
        If sender.CommandName="Update" Then
        
            Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("CorpCardConnectionString").ConnectionString)
                stCon.Open()
            
                Dim item As GridDataItem = DirectCast(RadGrid1.SelectedItems(0), GridDataItem)
	            TID = item("TID").Text

                Dim ddDept As DropDownList = DirectCast(DetailsView1.FindControl("ddDept"), DropDownList)
                Dim sACCT_UNIT As String = ddDept.SelectedValue.ToString()
                Dim ddActNum As DropDownList = DirectCast(DetailsView1.FindControl("ddActivity"), DropDownList)
                Dim sAcctNum As String = ddActNum.SelectedValue.ToString()
                Dim ddExpType As DropDownList = DirectCast(DetailsView1.FindControl("ddExpType"), DropDownList)
                sExpType = ddExpType.SelectedValue.ToString()
                Dim txtPurpose As textbox = DirectCast(DetailsView1.FindControl("txtBP"), textbox)
                Dim txtPersEnt As textbox = DirectCast(DetailsView1.FindControl("txtPersEnt"), textbox)
                Dim txtDestCity As textbox = DirectCast(DetailsView1.FindControl("txtDestCity"), textbox)
                Dim txtPartyInfo As textbox = DirectCast(DetailsView1.FindControl("txtPartyInfo"), textbox)
                
                sqlds_SelectedRec.UpdateCommand = "UPDATE [CorpCard_new].[dbo].[Trans] SET ACCT_UNIT=@ENTRYID, ActivityNum=@ActivityCode, ExpID=@ExpID, Purpose=@Purpose, EntertainWho=@EntertainWho, TravelTo=@TravelTo, ThirdPartyInfo=@ThirdPartyInfo, LastSaved=@LastSaved WHERE TID=@TID"
                sqlds_SelectedRec.UpdateParameters("TID").DefaultValue = TID
                sqlds_SelectedRec.UpdateParameters("ENTRYID").DefaultValue = sACCT_UNIT
                sqlds_SelectedRec.UpdateParameters("ExpID").DefaultValue = sExpType
                sqlds_SelectedRec.UpdateParameters("ActivityCode").DefaultValue = sAcctNum
                sqlds_SelectedRec.UpdateParameters("Purpose").DefaultValue = txtPurpose.text
                sqlds_SelectedRec.UpdateParameters("EntertainWho").DefaultValue = txtPersEnt.text
                sqlds_SelectedRec.UpdateParameters("TravelTo").DefaultValue = txtDestCity.text
                sqlds_SelectedRec.UpdateParameters("ThirdPartyInfo").DefaultValue = txtPartyInfo.text
                sqlds_SelectedRec.UpdateParameters("LastSaved").DefaultValue = System.DateTime.Now().ToString()
                
                sqlds_SelectedRec.Update()
                DetailsView1.DataBind()
            End Using

        End If
        
    End Sub
    

    Protected Sub ServerValidation1(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs)
            
       Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("DirectoryConnectionString").ConnectionString)
            stCon.Open()
            
            Dim ddExpType As DropDownList = DirectCast(DetailsView1.FindControl("ddExpType"), DropDownList)
            sExpType = ddExpType.SelectedValue.ToString()
            
            Dim txtBP As TextBox = DirectCast(DetailsView1.FindControl("txtBP"), TextBox)
            Dim txtPersEnt As TextBox = DirectCast(DetailsView1.FindControl("txtPersEnt"), TextBox) 
            Dim txtDestCity As TextBox = DirectCast(DetailsView1.FindControl("txtDestCity"), TextBox) 
            Dim txtPartyInfo As TextBox = DirectCast(DetailsView1.FindControl("txtPartyInfo"), TextBox) 

            Dim selCommand5 As New SqlCommand("SELECT * FROM [CorpCard_new].[dbo].[ExpType] WHERE ExpID = @ExpType", stCon)
            selCommand5.Parameters.Add("@ExpType", SqlDbType.Int).Value = sExpType
            Dim stDataReader As SqlDataReader = selCommand5.ExecuteReader
            If Not stDataReader.HasRows Then
                'no rows returned
            Else
                'rows returned
            While stDataReader.Read()
                bPurpose = CType(stDataReader.Item("ReqPurpose"), Boolean)
                bEntertain = CType(stDataReader.Item("ReqEntertainWho"), Boolean)
                bTravelTo  = CType(stDataReader.Item("ReqTravelTo"), Boolean)
                bThirdParty = CType(stDataReader.Item("ReqThirdParty"), Boolean)
            End While
                
            args.IsValid = True
            IsPurposeValid = True
            IsEntertainValid = True
            IsTravelToValid = True
            IsThirdPartyValid = True

            If bPurpose = True Then
                IsPurposeValid = ddExpType.SelectedValue = sExpType AND txtBP.Text.Length > 0 
            End If

            If bEntertain = True Then
                IsEntertainValid = ddExpType.SelectedValue = sExpType AND txtPersEnt.Text.Length > 0
            End If

            If bTravelTo = True Then
                IsTravelToValid = ddExpType.SelectedValue = sExpType AND txtDestCity.Text.Length > 0 
            End If

            If bThirdParty = True Then
                IsThirdPartyValid = ddExpType.SelectedValue = sExpType AND txtPartyInfo.Text.Length > 0
            End If

            If IsPurposeValid = True AND IsEntertainValid = True AND IsTravelToValid = True AND isThirdPartyValid = True Then
                args.IsValid = True
            Else
                'args.IsValid = False
                If IsPurposeValid = False Then
                    Dim cvBP As CustomValidator = CType(DetailsView1.FindControl("cvBP"), CustomValidator)
                    cvBP.IsValid = False
                End If
                If IsEntertainValid = False Then
                    Dim cvPE As CustomValidator = CType(DetailsView1.FindControl("cvPE"), CustomValidator)
                    cvPE.IsValid = False
                End If
                If IsTravelToValid = False Then
                    Dim cvDestCity As CustomValidator = CType(DetailsView1.FindControl("cvDestCity"), CustomValidator)
                    cvDestCity.IsValid = False
                End If
                If isThirdPartyValid = False Then
                    Dim cvPartyInfo As CustomValidator = CType(DetailsView1.FindControl("cvPartyInfo"), CustomValidator)
                    cvPartyInfo.IsValid = False
                End If
            End If
            End If
            Dim sIsValid As String = args.IsValid.ToString()
        End Using

    End Sub

Open in new window

0
Comment
Question by:Ahelbling
2 Comments
 
LVL 7

Assisted Solution

by:Camillia
Camillia earned 250 total points
ID: 41732167
I think you need to use "ReBind()" but not in Page_load.
0
 
LVL 42

Accepted Solution

by:
zephyr_hex earned 250 total points
ID: 41734792
I'm not familiar with that plugin, but my guess would be this is a binding issue, or, perhaps you need to enable View State ?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now