0

ユーザーがアイテムなどを検索できるページがあります。.ascx ページを使用して結果を grdview に表示します。

aspxページにはseacrhボックスとボタンしかなく、ボタンをクリックすると、テキストボックス内の値をascxページに渡し、グリッドビューに結果を入力します。しかし、デバッグ後、ボタンのクリック後にグリッドビューが null に設定されていることがわかりました。他のすべての値がそこにあり、結果はデー​​タベースから返されます。

誰か助けてください。私は過去数時間解決策を探していて、いくつかの異なることを試しましたが、まだどこにも行きません.

前もって感謝します

編集

これが私のコードです

aspxのページです。

<%@ Register Src="Search.ascx" TagName="Search" TagPrefix="uc1" %>
    <form id="form1" runat="server">
        <div class="content">
            <div style="padding:5px;">
                <b>Search</b>: <asp:TextBox runat="server" ID="txtSearch" />
                <asp:RequiredFieldValidator ErrorMessage="*" ValidationGroup="SearchGroup" ControlToValidate="txtSearch" ID="RequiredFieldValidator1"
                    runat="server" />
            </div>
            <div style="padding:5px;">
                <asp:Button Text="Search" runat="server" ValidationGroup="SearchGroup" OnClick="btnSearch_Click" ID="btnSearch" />
            </div>
        </div>
        <asp:ScriptManager runat="server" />
        <asp:UpdatePanel runat="server">
            <ContentTemplate>
                <div class="Results">
                    <uc1:Search ID="UserControl1" runat="server" />
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>

    </form>

ASCXページには次のものがあります

コードビハインド

Dim test As Object = txtSearch.Text

Dim StockList As cls_Stock_Col = MyLOTSDB.LoadStock_Col()
Try
    Dim dt As DataTable = New DataTable()
    Dim dcol As New DataColumn("TradeName", GetType(System.String))
    dt.Columns.Add(dcol)

    'Create an ID column for adding to the Datatable
    dcol = New DataColumn("PackSize", GetType(System.String))
    dt.Columns.Add(dcol)

    dcol = New DataColumn("PLU", GetType(System.String))
    dt.Columns.Add(dcol)

    dcol = New DataColumn("SOH", GetType(System.String))
    dt.Columns.Add(dcol)

    dcol = New DataColumn("RetailAsCurrency", GetType(System.String))
    dt.Columns.Add(dcol)

    For Each col As DataColumn In dt.Columns
        'Declare the bound field and allocate memory for the bound field.
        Dim bfield As New BoundField()
        'Initalize the DataField value.
        bfield.DataField = col.ColumnName
        'Initialize the HeaderText field value.

        Dim DisplayName As String = ""
        Dim DataFormat As String = ""
        Dim FieldType As Type = col.GetType()
        Dim StringLength As Int32

        GetFieldDetails(TheType, col.ColumnName, DisplayName, DataFormat, FieldType, StringLength)
        bfield.HeaderText = DisplayName

        If (DataFormat = "$0.00") Then
            bfield.DataFormatString = "{0:C2}"
        End If


        bfield.SortExpression = "col.ColumnName"
        'Add the newly created bound field to the GridView.
        GridView1.Columns.Add(bfield)
    Next

    GridView1.DataSource = StockList
    GridView1.DataBind()
Catch ex As Exception

End Try

デバッグでき、グリッドビューに列を追加しようとするとエラーがスローされます。

再度、感謝します

4

2 に答える 2

0
The aspx page only has a seacrh box and a button and on 
button click I want to pass the value from inside the textbox to the ascx page

これを行うには、呼び出しページでアクセスできる ascx コントロールのパブリック プロパティを指定します。

ascx コードビハインドの内部

private string searchText ;
Public string SetSearchText
{
      get { return searchText; }
      set { return searchText; }   
}  

ボタンクリック時の呼び出しページで、 ascx コントロールのプロパティを設定するだけです

ボタンクリックでメインページ内

YourAscxControl.SetSearchText= yourTextBox.Text.Trim();
于 2013-05-07T05:52:57.913 に答える