使用SqlWhereBuilder ASP.. NET服务器控件从数据库填充值

Using the SqlWhereBuilder ASP.NET Server Control to populate values from database

本文关键字:数据库 填充 服务器控件 SqlWhereBuilder ASP NET 使用      更新时间:2023-09-26

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

我的字段文件和操作符列表文件从xml正确填充。但是只有数据库中的值不填充。

我的。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" />
我CodeT.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>
我CodeT.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();
            }
        }
    }
}

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