0

我无法让 SqlWhereBuilder.js 用我的数据库中的值填充我的下拉列表。我已经指定了一个 valueentry 配置文件和一个相应的 .ascx 和 .ascx.cs 文件。我检查了 .ascx.cs 文件中的查询,它返回了我需要的值。但我无法使用这些值填充我的网站过滤器功能中的下拉列表。有什么我在这里遗漏的......我使用这个控件对吗?

我的 fieldsfile 和 operatorlists 文件从 xml 正确填充。但只有来自 db 的值不会填充。

我的 .aspx 文件:

<asp:Panel ID="panelContentCS" Style="overflow: hidden;" Width="650px" runat="server">
                                <div id="LayerCS" style="padding-left: 20px; padding-bottom: 10px; padding-top: 10px;
                                    padding-right: 10px;">
                                    <cc1:SqlWhereBuilder ID="swb1" runat="server" ClientCodeLocation="js/SqlWhereBuilder.js"
                                        FieldsFile="Configuration/fields.config" OperatorListsFile="Configuration/operatorLists.config"
                                        ValueEntryFile="Configuration/valueEntryDivs.config" NoConditionsText="Please Specify conditions"
                                        ButtonStyle="font-size: 10pt; background:whitesmoke;border:2px; border-style:solidline;"
                                        MainStyle="background-color:gainsboro;" ConditionCellStyle="border:1px solid black; padding:2px; background-color:#eeeeee"
                                        EditButtonText="Edit" DeleteButtonText="Delete" AddButtonText=" Add " EditButtonsHiliteColor="Gray"
                                        EditButtonsStyle="font-family: 'Arial'; font-size: 10pt; cursor:pointer;" ConditionDisplayStyle="font-family: 'Tahoma': font-size: 10pt; padding 2px;">
                                    </cc1:SqlWhereBuilder>
                                </div>
                            </asp:Panel>

我的 valueEntryDivs.config:

<valueEntry id="vCodeR" userControl="SQLBuilder/CodeR.ascx" />
<valueEntry id="vCodeQ" userControl="SQLBuilder/CodeQ.ascx" />
<valueEntry id="vCodeT" userControl="SQLBuilder/CodeT.ascx" />

我的代码 T.ascx:

    <%@ Control Language="C#" AutoEventWireup="false" CodeFile="CodeT.ascx.cs"     Inherits="CodeT" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:DropDownList id="ddCodeT" runat="server" DataValueField="CodeT" DataTextField="CodeT"></asp:DropDownList>

我的代码 T.ascx.cs:

public partial class CodeT : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int count = 0;
        int j = 0;

        DbDataReader rdr = null;
        DbProviderFactory provider = Framework.ConnectionClass.GetDbFactory();
        DbConnection conn = null;
        conn = Framework.ConnectionClass.GetConnection("Code"); conn.Open();
        DbCommand cmd = provider.CreateCommand();
        cmd.CommandText = "SELECT [VALUE] AS CodeT  FROM tb_Searchcache WHERE LabelName = 'CodeT'";
        cmd.Connection = conn;

        if (!this.IsPostBack)
        {
            try
            {
                rdr =  Framework.DBClass.GetReader(ref cmd);
                ddCodeT.DataSource = rdr;
                ddCodeT.DataBind();
                count = ddCodeT.Items.Count;
                while (j < count)
                {
                    ddCodeT.Items[j].Value = "'" + ddCodeT.Items[j].Value + "'";
                    j = j + 1;
                }
            }
            finally
            {
                if ((rdr != null))
                {
                    rdr.Close();
                }
                cmd.Dispose();
                if (conn.State != ConnectionState.Closed)
                    conn.Close();

            }
        }
    }
}
4

1 回答 1

0

在浪费了相当多的时间之后,我才意识到我需要将 AutoEventWireup 设置为“true”。回发从未触发任何事情!

于 2013-03-06T23:46:01.540 回答