无法在ascx页面中从codebehind设置label.text

时间:2015-10-28 17:06:06

标签: asp.net telerik telerik-grid radgrid ascx

我有一个Telerik Radgrid,它调用.ascx控件,允许用户编辑比实际Radgrid中显示的更大的数据集。这一切都很好,除了我试图设置文本的一个标签。它可以访问的原始数据只是一个ID,但我需要它来显示与该ID相关联的人名。因此,我创建了一个函数来获取所需的信息,然后设置标签文本。可悲的是,这不起作用。我完全为一个愚蠢的错误留下了空间,但我正试图弄清楚我做错了什么。我一个人工作,所以我甚至不能要求其他团队成员帮助表明我是多么愚蠢。这是我的代码:

ASCX.VB Codebehind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    lblParentID.Text = GetParentID(DataBinder.Eval(Container, "DataItem.PartnerID"))
End Sub

Protected Function GetParentID(ByVal UID As Integer) As String
    Dim strConnString As [String] = ConfigurationManager.ConnectionStrings("XXXX").ConnectionString
    Dim varParent As String
    Using con As New SqlConnection(strConnString)
        con.Open()
        Dim sqlParentCheck As String = "SELECT ParentID FROM [some table] WHERE PartnerID = @PID"
        Dim cmdParentCheck As New SqlCommand()
        Dim readerParentCheck As SqlDataReader
        cmdParentCheck.Parameters.AddWithValue("@PID", UID)
        cmdParentCheck.CommandType = Data.CommandType.Text
        cmdParentCheck.CommandText = sqlParentCheck
        cmdParentCheck.Connection = con
        readerParentCheck = cmdParentCheck.ExecuteReader()

        If readerParentCheck.HasRows Then
            Dim ParentID_O As Integer = readerParentCheck.GetOrdinal("ParentID")
            Dim ParentID As Integer = readerParentCheck.GetInt32(ParentID_O)
            If ParentID = 0 Then
                varParent = "Account Admin"
            Else
                Dim sqlParentName As String = "SELECT FirstName, LastName FROM Partners WHERE PartnerID = @PID"
                Dim cmdParentName As New SqlCommand()
                Dim readerParentName As SqlDataReader
                cmdParentName.Parameters.AddWithValue("@PID", ParentID)
                cmdParentName.CommandType = Data.CommandType.Text
                cmdParentName.CommandText = sqlParentName
                cmdParentName.Connection = con
                readerParentName = cmdParentName.ExecuteReader()
                If readerParentName.HasRows Then
                    Dim ParentFName_O As Integer = readerParentName.GetOrdinal("FirstName")
                    Dim ParentFName As String = readerParentName.GetString(ParentFName_O)
                    Dim ParentLName_O As Integer = readerParentName.GetOrdinal("LastName")
                    Dim ParentLName As String = readerParentName.GetString(ParentLName_O)
                    varParent = ParentFName & " " & ParentLName
                End If
            End If
            Return varParent
        End If
    End Using
End Function

ASCX:

<asp:label ID="lblParentID" runat="server"></asp:label>

ASPX:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" ShowFooter="true"
                AllowSorting="True" AutoGenerateColumns="False" ShowStatusBar="true" AllowFilteringByColumn="true"
                OnPreRender="RadGrid1_PreRender" Skin="Default" OnItemCreated="RadGrid1_ItemCreated" OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand">
                <MasterTableView Width="100%" CommandItemDisplay="None" DataKeyNames="PartnerID">
                    <Columns>
                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn UniqueName="AccountNumber" HeaderText="Account" DataField="AccountNumber">
                            <HeaderStyle Width="60px"></HeaderStyle>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="Company" HeaderText="Company" DataField="Company">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="FirstName" HeaderText="FirstName" DataField="FirstName">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="LastName" HeaderText="LastName" DataField="LastName">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="Email" HeaderText="Email" DataField="Email">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <EditFormSettings UserControlName="UserDetails.ascx" EditFormType="WebUserControl">
                        <EditColumn UniqueName="EditCommandColumn1">
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>
                <ClientSettings>
                    <ClientEvents OnRowDblClick="RowDblClick" OnPopUpShowing="onPopUpShowing" />
                </ClientSettings>
            </telerik:RadGrid>

0 个答案:

没有答案