English 中文(简体)
达格·哈马舍尔德图书馆无线电台
原标题:Radio buttom event in SharePoint WebPart not working

我正试图建立一个搜索工具。 它可以在我的搜寻纽扣上搜寻,并作出反应。 我增加了一些无线电台,用户可以用来确定某些环境。 我希望网站每当无线电台的检查发生变化时都会进行新的搜索,但这是我不得不做的事。

我试图在上做些什么。 答案是,但它没有帮助。

Here is my code

public class HelloWorld : Microsoft.SharePoint.WebPartPages.WebPart
{
    Button btn;
    TextBox textBx;
    string _myProperty = "";
    DataTable resultsDataTable = new DataTable();
    RadioButton exactSearch;
    RadioButton wildSearch;

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [System.ComponentModel.Category("My Property Group")]
    [WebDisplayName("MyProperty")]
    [WebDescription("Meaningless Property")]
    public string MyProperty
    {
        get
        {
            if (_myProperty == null)
            {
                _myProperty = "Hello SharePoint";
            }
            return _myProperty;
        }
        set { _myProperty = value; }
    }

    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        textBx = new TextBox();
        textBx.Text = "";

        btn = new Button();
        btn.Text = "Search";

        exactSearch = new RadioButton();
        exactSearch.GroupName = "searchSetting";
        exactSearch.Checked = false;

        wildSearch = new RadioButton();
        wildSearch.GroupName = "searchSetting";
        wildSearch.Checked = true;

        //Events
        btn.Click += new EventHandler(btn_Click);
        wildSearch.CheckedChanged += new EventHandler(wildSearch_CheckedChanged);

        //Adding to controls
        this.Controls.Add(btn);
        this.Controls.Add(textBx);
        this.Controls.Add(exactSearch);
        this.Controls.Add(wildSearch);
    }

    void wildSearch_CheckedChanged(object sender, EventArgs e)
    {
        search();
    }

    void btn_Click(object sender, EventArgs e)
    {
        search();
    }

    protected override void Render(HtmlTextWriter writer)
    {
        //Title
        writer.Write("Super Lookup Service <br/>");

        //Search block
        textBx.RenderControl(writer);
        writer.Write("&nbsp;&nbsp;");
        btn.RenderControl(writer);
        writer.Write("<br/>");
        writer.Write("Exact Search ");
        exactSearch.RenderControl(writer);
        writer.Write("&nbsp;&nbsp;");
        writer.Write("Wild Search ");
        wildSearch.RenderControl(writer);
        writer.Write("<br/><br/>");

        //Search results
        if (resultsDataTable.Rows.Count > 0)
        {
            writer.Write("<b> {0} Results:</b><br/>", resultsDataTable.Rows.Count);
            foreach (DataRow row in resultsDataTable.Rows)
            {
                writer.Write("<a href="{0}">{1}</a> ({2}) - size: {3}<br/>", row["path"].ToString(), row["title"].ToString(), row["author"].ToString(), row["Size"].ToString());
            }
        }

        else
        {
            writer.Write("<b>0 Results:</b>");
        }
    }

    private void search()
    {
        using (SPSite site = new SPSite(SPContext.Current.Site.ID))
        {
            FullTextSqlQuery query = new FullTextSqlQuery(site);
            string queryText = "";

            if (wildSearch.Checked == true)
            {
                queryText = "SELECT title, path, author, Size from Scope() where title LIKE  %" + textBx.Text + "%  order by title asc ";
            }
            else if (exactSearch.Checked == true)
            {
                queryText = "SELECT title, path, author, Size from Scope() where title =  " + textBx.Text + "  order by title asc ";
            }

            query.QueryText = queryText;
            query.ResultTypes = ResultType.RelevantResults;
            query.RowLimit = 3000;

            ResultTableCollection resultTables = query.Execute();
            if (resultTables.Count > 0)
            {
                ResultTable relevantResults = resultTables[ResultType.RelevantResults];
                resultsDataTable.Load(relevantResults, LoadOption.OverwriteChanges);
            }
        }
    }
}

希望能帮助我。

BR

最佳回答

当在OnCreateChildControl上设立无线电台,你必须把无线电台的自动PostBack财产归为真实的,如果它不背后,也不会对事件火上.。

wildSearch.AutoPostBack = true;
问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签