来自字符串的Combobox数据绑定不起作用

时间:2013-09-04 09:27:01

标签: asp.net arrays data-binding combobox telerik

在我的应用程序中,当用户添加/编辑记录时,它会弹出一个radwindow。

我在combox上使用了ondatabound函数,但我的代码无效。

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Allowance.aspx.vb" Inherits="Payroll_Allowance" %>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Edit Payroll Allowance</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadSplitter ID="RadSplitter1" runat="server" Width="100%" Height="100%" Orientation="Horizontal">

        <telerik:RadPane ID="rpContent" runat="server">
 <asp:Panel ID="Panel1" runat="server" Width="100%"  CssClass=thePanel>
        <asp:Table ID="Table0" runat="server" Height="100%">
            <asp:TableRow>
                <asp:TableCell Font-Bold="true" font-size="10pt" CssClass=theHead>
        Payroll Allowance   
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </asp:Panel>
    <telerik:RadToolBar ID="rtbMain" runat="server" Width="100%">
    <Items>
    <telerik:RadToolBarButton Width="80px" Value="Add" Text="Add" CausesValidation="false"></telerik:RadToolBarButton>
    <telerik:RadToolBarButton IsSeparator="true"></telerik:RadToolBarButton>
  <%--  <telerik:RadToolBarButton Width="80px" Value="Edit" Text="Edit" CausesValidation="false" Enabled=false></telerik:RadToolBarButton>
    <telerik:RadToolBarButton IsSeparator="true"></telerik:RadToolBarButton>
    <telerik:RadToolBarButton Width="80px" Value="Delete" Text="Delete" CausesValidation="false" Enabled=false></telerik:RadToolBarButton>
    <telerik:RadToolBarButton IsSeparator="true"></telerik:RadToolBarButton>
  --%>  
    <telerik:RadToolBarButton Width="80px" Value="Report" Text="Report" visible=false CausesValidation="false"></telerik:RadToolBarButton>
    <telerik:RadToolBarButton IsSeparator="true"></telerik:RadToolBarButton>

    </Items>
    </telerik:RadToolBar>
    <div id="printarea">
    <asp:Table ID="tblHistory" width=800px runat="server" >
    <asp:TableRow>
    <asp:TableCell>
    <asp:Table ID="Table1" runat="server" Width=650 BorderStyle=None>
    <asp:TableRow>
    <asp:TableCell CssClass=fieldheader Width=150>Staff Name</asp:TableCell>
    <asp:TableCell Width=250><asp:Label ID="lbStaffName" runat=server></asp:Label></asp:TableCell>
    <asp:TableCell CssClass=fieldheader Width=150>Staff No.</asp:TableCell>
    <asp:TableCell Width=250><asp:Label ID="lbStaffNo" runat=server></asp:Label></asp:TableCell>

    </asp:TableRow>
    </asp:Table>
    </asp:TableCell>
    </asp:TableRow>
    </asp:Table>
    <br />
    <telerik:RadGrid ID="rgAllowance" runat="server" DataSourceID="ldsAllowance"
                    GridLines="None" Width="800px" AllowSorting="True" AutoGenerateColumns="false" AllowFilteringByColumn="false" ShowGroupPanel=false ShowFooter="False" 
                    AllowPaging="True" PageSize="15">
                    <PagerStyle Position="TopAndBottom" />

        <ClientSettings EnablePostBackOnRowClick="True" AllowColumnsReorder="True" AllowDragToGroup="false" ReorderColumnsOnClient="True">
            <Selecting AllowRowSelect="True" />             
        </ClientSettings>


                    <MasterTableView DataSourceID="ldsAllowance" DataKeyNames="AllowanceID" >
                        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                        <RowIndicatorColumn>
                            <HeaderStyle Width="10px"></HeaderStyle>
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="10px"></HeaderStyle>
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="AllowanceID" HeaderText="Allowance ID" ReadOnly="True"
                                SortExpression="AllowanceID" UniqueName="AllowanceID" Visible=false>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PPSCompanyCode" HeaderText="Allowance Code" ReadOnly="True"
                                SortExpression="PPSCompanyCode" UniqueName="PPSCompanyCode"><ItemStyle Font-Underline="True" BackColor=White ForeColor="Blue" BorderColor=ActiveBorder/>
                            </telerik:GridBoundColumn>                            
                            <telerik:GridBoundColumn DataField="EntitleFrom" HeaderText="Entitle From" ReadOnly="True"  DataFormatString="{0:dd-MMM-yyyy}"
                                SortExpression="EntitleFrom" UniqueName="EntitleFrom"><ItemStyle BackColor=White  BorderColor=ActiveBorder />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="EntitleTo" HeaderText="Entitle To" ReadOnly="True"  DataFormatString="{0:dd-MMM-yyyy}"
                                SortExpression="EntitleTo" UniqueName="EntitleTo"><ItemStyle BackColor=White BorderColor=ActiveBorder/>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="AllowanceAmount" HeaderText="Remarks" ReadOnly="True" DataFormatString="{0:N}"
                                SortExpression="AllowanceAmount" UniqueName="AllowanceAmount"><ItemStyle BackColor=White BorderColor=ActiveBorder/>
                            </telerik:GridBoundColumn>



                            </Columns>
                    </MasterTableView>
                </telerik:RadGrid>
    </div>
        </telerik:RadPane>
    </telerik:RadSplitter>
    <telerik:RadWindow ID="RadWindow1" runat="server" Width="580px" Height="300px" Behaviors="Close"
        Title="Add/Modify Payroll Allowance" >
        <ContentTemplate>
            <asp:Table ID="Table2" runat="server" Width="100%" Height="100%">

                <asp:TableRow >
                <asp:TableCell CssClass="editheader">Allowance Code: </asp:TableCell>
                <asp:TableCell>
                    <telerik:RadComboBox ID="dfAllowanceCode" runat="server" Width="250px"
                    AppendDataBoundItems="true" AutoPostBack="true" DataTextField="ACode"
                    OnDataBound="dfAllowanceCode_DataBound">
                     <Items>
                        <telerik:RadComboBoxItem Text="--Select--" Value="" />
                    </Items>
                    </telerik:RadComboBox>

                </asp:TableCell>
                  </asp:TableRow>

                <asp:TableRow>   
                    <asp:TableCell CssClass="editheader">Entitle From: </asp:TableCell>
                    <asp:TableCell>
                        <asp:HiddenField ID="dfAllowanceID" Value="0" runat="server" />
                        <telerik:RadDatePicker ID="dfStartDate" runat="server" Width="150px" DateInput-DateFormat="dd-MMM-yyyy" Enabled="true">
                        </telerik:RadDatePicker>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="* Required"
                            ControlToValidate="dfStartDate"></asp:RequiredFieldValidator>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell CssClass="editheader">Entitle To: </asp:TableCell>
                    <asp:TableCell>
                       <telerik:RadDatePicker ID="dfEndDate" runat="server" Width="150px" DateInput-DateFormat="dd-MMM-yyyy" Enabled="true">
                        </telerik:RadDatePicker>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="* Required"
                            ControlToValidate="dfEndDate"></asp:RequiredFieldValidator>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell CssClass="editheader">Amount: </asp:TableCell>
                    <asp:TableCell>
                        <telerik:RadNumericTextBox  ID="dfAmount" runat="server" Width="125px" Enabled="true" 
                        NumberFormat-DecimalDigits="2" >
                        </telerik:RadNumericTextBox >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="* Required"
                            ControlToValidate="dfAmount"></asp:RequiredFieldValidator>
                    </asp:TableCell>
                </asp:TableRow>

                <asp:TableRow>
                    <asp:TableCell BackColor="#EEEEEE" ColumnSpan="2" HorizontalAlign="Center">
                        <asp:Button ID="btnSave" runat="server" Text="Save" Width="80px" />&nbsp;&nbsp;
                        <asp:Button ID="btnDelete" runat="server" Text="Delete" Width="80px" CausesValidation="false" />
                        <asp:Button ID="btnCancel" runat="server" Text="Close" Width="80px" CausesValidation="false" />
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
        </ContentTemplate>
    </telerik:RadWindow>

    <asp:LinqDataSource ID="ldsAllowance" runat="server" ContextTypeName="dcHRISDataContext"
        OrderBy="EntitleFrom desc,AllowanceID desc"
        TableName="HRIS_PPSAllowances" Where="SID==@SID">
         <WhereParameters>
            <asp:QueryStringParameter DefaultValue="0" Name="SID" QueryStringField="SID"
                Type="Int32" />                
        </WhereParameters>
    </asp:LinqDataSource>

    </form>
</body>
</html>

代码背后:

Protected Sub dfAllowanceCode_DataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemEventArgs) Handles dfAllowanceCode.DataBound


    Dim ACode As String = "PPS123, PPS22323, PPS5454, PPS1231"

    Try
        Dim i As Integer = 0

        Dim arrList As New ArrayList()
        arrList.AddRange(ACode.Split(","))

        For i = 0 To arrList.Count - 1
            dfAllowanceCode.Items.Add(New Telerik.Web.UI.RadComboBoxItem(arrList.Item(i).ToString, i))
        Next

    Catch ex As Exception
        Response.Write("An Error Occurred: " & e.ToString())
    Finally

    End Try
End Sub

0 个答案:

没有答案