radcombo gets loaded with data alternatively in raddatagrid ?

1 posts, 0 answers
  1. Saravanan
    Saravanan avatar
    11 posts
    Member since:
    Jul 2009

    Posted 24 Mar 2010 Link to this post

    i have a rad data grid with rad combo in it but the data gets laded from the DB alternatively. i might be missing or might have done something wrong.Hope to get a reply....


    My aspx.Vb

    Imports System.Data
    Imports ExceptionHandling
    Imports NDSBLL
    Imports NDSDAL
    Imports System.DirectoryServices
    Imports System.Security.Principal
    Imports AjaxControlToolkit
    Imports Telerik.Web.UI


    Partial Class Utilities_SapDataConvertion
        Inherits System.Web.UI.Page
        Public strResult As String()
        Public objUtilitiesinfo As NDSBLL.UtilitiesInfo = Nothing
        Public objUtilitiesDal As NDSDAL.UtilitiesDal = Nothing
        Public objinfo As NDSBLL.AdminInfo = Nothing
        Public objdal As NDSDAL.AdminDal = Nothing
        Dim strErrorLog As String = ConfigurationManager.AppSettings.Get("ErrorLog")
        Dim dsCustomer As DataSet
        Dim strPage As String


        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                AccessRights()
                If Not Page.IsPostBack Then
                    Session("UserId") = strResult(2)

                    PopulateGrid()
                End If
           
            Catch ex As Exception
                ErrorHandler.RaiseError(ex, strErrorLog)
            End Try
        End Sub
        Private Sub AccessRights()
            Try
                strPage = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.Url.AbsolutePath)
                Dim struser As New WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent())
                objdal = New NDSDAL.AdminDal()
                objinfo = New NDSBLL.AdminInfo()
                objinfo.LoginId = ExtractUserName(struser.Identity.Name)
                Dim intLen As Integer
                intLen = strPage.IndexOf(".")
                objinfo.FormName = strPage.Substring(0, intLen)
                strResult = objdal.ValidateUser(objinfo)
                ''''''''''''''''
                If (strResult(0) = True And strResult(1) = True) Then
                    btnConvert.Enabled = True
                ElseIf (strResult(0) = False And strResult(1) = False) Then
                    Dim apnlUtilities As AccordionPane = CType(Master.FindControl("apnlUtilities"), AccordionPane)
                    Dim lnkSapContractConvert As LinkButton = CType(apnlUtilities.FindControl("lnkSapContractConvert"), LinkButton)
                    Response.Redirect("~/UnAuthorization.aspx?file=" + lnkSapContractConvert.Text.ToString, False)
                    Exit Sub
                ElseIf (strResult(0) = True And strResult(1) = False) Then
                    btnConvert.Enabled = False
                ElseIf (strResult(0) = False And strResult(1) = True) Then
                    btnConvert.Enabled = True
                End If
                ''''''''''''''''
            Catch ex As Exception
                ErrorHandler.RaiseError(ex, strErrorLog)
            End Try
        End Sub
        Public Function ExtractUserName(ByVal path As String) As String
            Try
                Dim userPath As String() = path.Split(New Char() {"\"c})

                Return userPath(userPath.Length - 1)
            Catch ex As Exception
                ErrorHandler.RaiseError(ex, strErrorLog)
            End Try
        End Function


        Private Sub PopulateGrid()
            Try
                Dim dv As New DataView
                Dim dtStandard As New DataTable

                objUtilitiesinfo = New NDSBLL.UtilitiesInfo
                objUtilitiesDal = New NDSDAL.UtilitiesDal
                If (ViewState("sortExpr")) IsNot Nothing Then
                    dv.Table = objUtilitiesDal.GetSapContractConvert().Tables(0)
                    dv.Sort = DirectCast(ViewState("sortExpr"), String) + " " + ViewState("sortDirection")
                Else
                    dv = objUtilitiesDal.GetSapContractConvert().Tables(0).DefaultView
                End If
                dtStandard = objUtilitiesDal.GetSapContractConvert().Tables(1)
                ViewState("dtStandard") = dtStandard
                gvSap.DataSource = dv
                gvSap.DataBind()

            Catch ex As Exception
                ErrorHandler.RaiseError(ex, strErrorLog)
            Finally
                objUtilitiesinfo = Nothing
                objUtilitiesDal = Nothing
            End Try
        End Sub
        Private Sub Save()
            Try
                Dim intOutput As Integer
                Dim i As Integer
                objUtilitiesinfo = New NDSBLL.UtilitiesInfo
                objUtilitiesDal = New NDSDAL.UtilitiesDal

                objUtilitiesinfo.UserId = Session("UserId")

                For i = 0 To gvSap.Items.Count - 1
                    If DirectCast(gvSap.Items(i).FindControl("chkSelection"), CheckBox).Checked Then
                        txtCheckboxCount.Text = txtCheckboxCount.Text.Trim + 1
                        txtCheckboxCount.Text = txtCheckboxCount.Text.Trim
                        Dim ddlStandardCode As DropDownList
                        ddlStandardCode = CType(gvSap.Items(i).FindControl("ddlStandardCode"), DropDownList)
                        objUtilitiesinfo.StandardCode = ddlStandardCode.SelectedValue.ToString()
                        objUtilitiesinfo.SapContractNo = CType(gvSap.Items(i).FindControl("lblContractNo"), Label).Text
                        objUtilitiesinfo.CustomerCode = CType(gvSap.Items(i).FindControl("lblCustomerId"), Label).Text
                        objUtilitiesinfo.StandardType = CType(gvSap.Items(i).FindControl("lblPinType"), Label).Text
                        objUtilitiesinfo.Status = CType(gvSap.Items(i).FindControl("lblStatus"), Label).Text

                        intOutput = objUtilitiesDal.InsertSapContractConvert(objUtilitiesinfo)
                    End If
                Next
                'If intOutput = -1 Then
                '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Msg", "<script>alert('Convertion failed');</script>", False)
                If (txtCheckboxCount.Text = "0") Then
                    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Msg", "<script>alert('Please select atleast one SAP Contract to proceed further');</script>", False)

                End If
                If intOutput = 1 Then
                    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Msg", "<script>alert('The Selected SAP Contracts are converted to NDS Contracts');</script>", False)
                End If
            Catch ex As Exception
                ErrorHandler.RaiseError(ex, strErrorLog)
            Finally
                objUtilitiesinfo = Nothing
                objUtilitiesDal = Nothing
            End Try
        End Sub
        ''Protected Sub gvSap_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvSap.PageIndexChanging
        ''    Try
        ''        gvSap.PageIndex = e.NewPageIndex
        ''        PopulateGrid()
        ''    Catch ex As Exception
        ''        ErrorHandler.RaiseError(ex, strErrorLog)
        ''    End Try
        ''End Sub


        Protected Sub btnConvert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConvert.Click
            Try
                Save()
                'ddlCustomer.SelectedIndex = -1
                'rdbStandard.Checked = True
                'ddlStandardCode.SelectedIndex = -1
                'ddlStatus.SelectedIndex = -1

                PopulateGrid()

            Catch ex As Exception
                ErrorHandler.RaiseError(ex, strErrorLog)
            End Try
        End Sub

        Protected Sub btnCheckAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCheckAll.Click
            ''Dim i As Integer
            ''Try
            ''    For i = 0 To gvSap.Rows.Count - 1
            ''        CType(gvSap.Rows(i).FindControl("chkSelection"), CheckBox).Checked = True
            ''    Next
            ''Catch ex As Exception
            ''    ErrorHandler.RaiseError(ex, strErrorLog)
            ''End Try
        End Sub

        Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
            ''Dim i As Integer
            ''Try
            ''    For i = 0 To gvSap.Rows.Count - 1
            ''        If DirectCast(gvSap.Rows(i).FindControl("chkSelection"), CheckBox).Checked Then
            ''            CType(gvSap.Rows(i).FindControl("chkSelection"), CheckBox).Checked = False
            ''        End If
            ''    Next
            ''Catch ex As Exception
            ''    ErrorHandler.RaiseError(ex, strErrorLog)
            ''End Try
        End Sub



        ''Protected Sub gvSap_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles gvSap.ItemDataBound
        ''    Try
        ''        objUtilitiesinfo = New NDSBLL.UtilitiesInfo
        ''        objUtilitiesDal = New NDSDAL.UtilitiesDal
        ''        Dim strStandardCode As String

        ''        Dim lblContract As Label
        ''        ''lblContract = e.Row.FindControl("lblContractNo")
        ''        lblContract = e.Item.FindControl("lblContractNo")
        ''        ''If e.Row.RowType = DataControlRowType.DataRow Then
        ''        Dim gridDataItem As GridDataItem = TryCast(e.Item, GridDataItem)
        ''        Select Case e.Item.ItemType
        ''            Case GridItemType.Item

        ''                Dim ddlStandardCode As RadComboBox
        ''                ''ddlStandardCode = CType(e.Row.FindControl("ddlStandardCode"), DropDownList)
        ''                ddlStandardCode = CType(e.Item.FindControl("ddlStandardCode"), RadComboBox)
        ''                ddlStandardCode.DataSource = ViewState("dtStandard")
        ''                ddlStandardCode.DataTextField = "nvchStandardCode"
        ''                ddlStandardCode.DataValueField = "intStandardId"
        ''                ddlStandardCode.DataBind()

        ''                strStandardCode = GetLocalResourceObject("DefaultStandardcode").ToString()
        ''                'ddlStandardCode.Items.FindByText(strStandardCode).Selected = True
        ''                ddlStandardCode.Items.FindItemByText(strStandardCode).Selected = True

        ''            Case GridItemType.Item
        ''                'If e.Row.RowType = DataControlRowType.DataRow Then
        ''                If (CType(e.Item.FindControl("chkSelection"), CheckBox).Checked) = True Then
        ''                    e.Item.Visible = False
        ''                    'End If
        ''                End If
        ''        End Select
        ''    Catch ex As Exception
        ''        ErrorHandler.RaiseError(ex, strErrorLog)
        ''    Finally
        ''        objUtilitiesinfo = Nothing
        ''        objUtilitiesDal = Nothing
        ''    End Try
        ''End Sub

        Protected Sub gvSap_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles gvSap.ItemDataBound
            Try
                objUtilitiesinfo = New NDSBLL.UtilitiesInfo
                objUtilitiesDal = New NDSDAL.UtilitiesDal
                Dim strStandardCode As String

                Dim lblContract As Label
                ''lblContract = e.Row.FindControl("lblContractNo")
                lblContract = e.Item.FindControl("lblContractNo")
                ''If e.Row.RowType = DataControlRowType.DataRow Then
                Dim gridDataItem As GridDataItem = TryCast(e.Item, GridDataItem)
                Select Case e.Item.ItemType
                    Case GridItemType.Item

                        Dim ddlStandardCode As RadComboBox
                        ''ddlStandardCode = CType(e.Row.FindControl("ddlStandardCode"), DropDownList)
                        ddlStandardCode = CType(e.Item.FindControl("ddlStandardCode"), RadComboBox)
                        ddlStandardCode.DataSource = ViewState("dtStandard")
                        ddlStandardCode.DataTextField = "nvchStandardCode"
                        ddlStandardCode.DataValueField = "intStandardId"
                        ddlStandardCode.DataBind()

                        strStandardCode = GetLocalResourceObject("DefaultStandardcode").ToString()
                        'ddlStandardCode.Items.FindByText(strStandardCode).Selected = True
                        ddlStandardCode.Items.FindItemByText(strStandardCode).Selected = True

                    Case GridItemType.Item
                        'If e.Row.RowType = DataControlRowType.DataRow Then
                        If (CType(e.Item.FindControl("chkSelection"), CheckBox).Checked) = True Then
                            e.Item.Visible = False
                            'End If
                        End If
                End Select
            Catch ex As Exception
                ErrorHandler.RaiseError(ex, strErrorLog)
            Finally
                objUtilitiesinfo = Nothing
                objUtilitiesDal = Nothing
            End Try
        End Sub
    End Class

    My aspx

    <%@ Page Language="VB"
            Theme="NDS"
            MasterPageFile="~/NDSMASTER2.master"
            AutoEventWireup="false"
            CodeFile="SAPContractConvertion.aspx.vb"
            Inherits="Utilities_SapDataConvertion" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="contentplaceholder1" runat="Server">
       <script language="javascript" type="text/javascript">
       
       </script>

    <table style="width:100%; font-family:Verdana; font-size:11px;"  border="0">
        <tr class="TRHeader">
            <td align="center" colspan="2">
                <span>Conversion of Sap Data</span>
            </td>        
        </tr>
        <tr>
          <td style="height:6%" colspan="2"></td>
        </tr>
        <tr>
            <td style="width: 82px" ><asp:TextBox ID="txtCheckboxCount" runat="server" Text="0" Visible ="false" ></asp:TextBox>
            </td>
            </tr>  
        <%--<tr>
            <td style="width:20%">
                <asp:label ID="lblCustomer"  CssClass="label"  runat="server" Text="Customer" ></asp:label>
                <span style="font-weight:bold; color:red">*</span>
            </td>    
            <td>
                <asp:DropDownList ID="ddlCustomer" SkinID="ddlMedium" runat="server" ></asp:DropDownList>
            </td>       
        </tr>
        <tr>
             <td>
                    <asp:Label ID="lblPinType" runat="server" CssClass="label" Text="Pin Type"></asp:Label>
                    <span style="font-weight:bold; color:Red">*</span>
            </td>
            <td>
                    <asp:RadioButton ID="rdbStandard" runat="server" Checked="true" GroupName ="select" tabIndex="8"></asp:RadioButton>
                    <asp:Label ID="lblStandard" runat="server" CssClass="label" Text="Standard"></asp:Label> &nbsp;                           
                    
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                    <asp:RadioButton ID="rdbNonStandard" runat="server" GroupName="select" tabIndex="10"></asp:RadioButton>
                    <asp:Label ID="lblNonStandard" runat="server" CssClass="label" Text="Non Standard"></asp:Label> &nbsp;                
            </td>
        </tr>
        <tr>
            <td>
                    <asp:Label ID="lblStandardCode" CssClass="label" runat="server" Text="Standard"></asp:Label>
                    <span style="font-weight:bold; color:red">*</span>
            </td>
            <td>
                    <asp:DropDownList ID="ddlStandardCode" runat="server" SkinID="ddlMedium" ToolTip="Please Select a Standard Code" tabIndex="6"></asp:DropDownList>
            </td>         
        </tr>
        <tr>
            <td>
                    <asp:Label ID="lblStatus" cssClass="label" runat="server" Text="Status"></asp:Label>
                        
            </td>
            <td>
                    <asp:DropDownList ID="ddlStatus" runat="server" SkinID="ddlMedium" ToolTip="Select Status" TabIndex="9"></asp:DropDownList>
            </td>
        </tr>--%>
        
        <tr>
          <td style="height:20%" colspan="2"></td>
        </tr>
        <tr>
          <td style="height:20%" colspan="2"></td>
        </tr>
        <tr>
            <td colspan="2" align ="center" >
              <%--  <asp:Panel ID="pnlSap" runat="server" Height="300px" Width="650px" ScrollBars="Auto">--%>
                        
                        
      <%--'-----------------------------------------------------------------------------------------%>                  
                      
                         <telerik:RadGrid ID="RadgvSap" runat="server"  AllowMultiRowSelection ="true" AllowMultiRowEdit ="true" AllowSorting="true"  AutoGenerateColumns = "false"
                            AllowCustomPaging = "true"   
                            HeaderStyle-BackColor="Silver" >
                             <ClientSettings  >
                             <Selecting  AllowRowSelect="true"  EnableDragToSelectRows="true"/>
                             </ClientSettings>
                           <MasterTableView   >
                           <Columns>
                           
                            <telerik:GridClientSelectColumn Visible ="true"  ItemStyle-HorizontalAlign = "Left"  UniqueName = "chkSelection" HeaderText = "Selection"  />
                           
                           <telerik:GridBoundColumn  DataField="vchCustomer"  HeaderText="Customer" SortExpression = "vchCustomer">
                           <HeaderStyle HorizontalAlign = "Center"/>
                           <ItemStyle HorizontalAlign="Left" Width="20%" />
                           </telerik:GridBoundColumn>
                            
                           <telerik:GridBoundColumn  DataField="vchContractCode"  HeaderText="SAP Contract" SortExpression = "vchContractCode">
                           <HeaderStyle HorizontalAlign = "Center"/>
                           <ItemStyle HorizontalAlign="Left" Width="10%" />
                           </telerik:GridBoundColumn>
                            
                            <telerik:GridBoundColumn  DataField="vchDescription"  HeaderText="SAP Desc" SortExpression = "vchDescription">
                           <HeaderStyle HorizontalAlign = "Justify"/>
                           <ItemStyle HorizontalAlign="Left" Width="20%" />
                           </telerik:GridBoundColumn>
                            
                             <telerik:GridBoundColumn  DataField="vchPinType"  HeaderText="Pin Type" SortExpression = "vchPinType">
                           <HeaderStyle HorizontalAlign = "Center"/>
                           <ItemStyle HorizontalAlign="Left" Width="20%" />
                           </telerik:GridBoundColumn>
                            
                            <telerik:GridTemplateColumn Visible = "true" HeaderText="StandardCode">
                            <ItemTemplate>
                            <telerik:RadComboBox ID="ddlStandardCode" runat = "Server" EnableLoadOnDemand="true">
                            </telerik:RadComboBox>
                            </ItemTemplate>
                            </telerik:GridTemplateColumn>
                           
                           <telerik:GridBoundColumn  DataField="vchStatus"  HeaderText="Status" SortExpression = "vchStatus">
                           <HeaderStyle HorizontalAlign = "Center"/>
                           <ItemStyle HorizontalAlign="Left" Width="5%" />
                           </telerik:GridBoundColumn>
                           
                           
                           </Columns>
                           </MasterTableView>
                    </telerik:RadGrid>
                                 
               <%-- </asp:Panel> --%>
                </td> </tr>
                <tr></tr> <tr></tr><tr></tr><tr></tr>
                <%--<tr><td align ="center" >
                    <asp:Button ID="btnConvert" runat="server" Text="Convert to NDS Contract"/>     
                </td></tr>         --%>    
        

    </table>
    <table style="width :650px">
    <tr>
    <td align ="center" style="width: 2754px" >
    <asp:Button  ID="btnConvert" runat="server" Text="Convert to NDS Contract"/>     
    <asp:Button  ID="btnCheckAll" runat="server" Text="Check All"/>     
    <asp:Button  ID="btnReset" runat="server" Text="Reset"/>
    </td>
    </tr>

    </table>  
       
    </asp:Content>  















Back to Top