更新面板中的asp.net gridview,使内容可见并更新

发布于 2024-07-15 20:28:54 字数 2253 浏览 6 评论 0原文

目前,我的页面上有一个动态创建的网格视图。 当用户在文本框中输入内容并按下按钮时,整个页面会刷新以填充网格视图并使其可见。 我不想再这样了。 我将如何使用 UpdatePanel 使 gridview 可见并填充它?

<div class="span-93 prepend-2 top">
        <strong>Enter  Number</strong><br />
        <asp:TextBox ID="PartNumber" runat="server" Width="100"></asp:TextBox>
        <asp:Button ID="CreateButton" runat="server" Width="85" Text="Locate" OnClick="CreateButton_Click" />
    </div>
<asp:Label ID="Select" runat="server" Font-Bold="true" Text="Select choice" Visible="false"></asp:Label><br />
            <ajax:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:GridView ID="GridView" Visible="false" runat="server"  HeaderStyle-Width="200" HeaderStyle-BackColor="#2B6292" HeaderStyle-ForeColor="White" 
                    AllowSorting="true" AllowPaging="true" Width="600" AutoGenerateColumns="False" OnRowCreated="GridView_OnRowCreated" 
                    DataKeyNames="Id" onsorting="GridView_OnSort">
                        <Columns>
                            ...
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <ajax:AsyncPostBackTrigger ControlID="CreateButton"/>
                </Triggers>
            </ajax:UpdatePanel>

显然,页面上还有另一个名为 CreateButton 的按钮,它将填充 gridview 并使其可见,以便用户可以从中进行选择。 这可能吗? 提前致谢。

编辑:将代码绑定到gridview:

    protected void Create_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Number.Text))
            {
                BLL newbll = new BLL();
                Database.DataTable tempTable = newbll.GetItemByPartNumber(Number.Text);

                if (Table.Count != 0)
                {
                DataTable table = tempTable ;

                string[] VID = { "Id" };
                GridviewDiv.Visible = true;
                GridView.DataSource = table;
                GridView.DataKeyNames = VID;
                GridView.DataBind();
            }
        }
    }

Currently, I have a dynamically created gridview on my page. When a user enters something in a textbox and presses a button, the whole page refreshes to populate the gridview and make it visible. I do not want that anymore. How would I go about using the UpdatePanel to make the gridview visible and populate it?

<div class="span-93 prepend-2 top">
        <strong>Enter  Number</strong><br />
        <asp:TextBox ID="PartNumber" runat="server" Width="100"></asp:TextBox>
        <asp:Button ID="CreateButton" runat="server" Width="85" Text="Locate" OnClick="CreateButton_Click" />
    </div>
<asp:Label ID="Select" runat="server" Font-Bold="true" Text="Select choice" Visible="false"></asp:Label><br />
            <ajax:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:GridView ID="GridView" Visible="false" runat="server"  HeaderStyle-Width="200" HeaderStyle-BackColor="#2B6292" HeaderStyle-ForeColor="White" 
                    AllowSorting="true" AllowPaging="true" Width="600" AutoGenerateColumns="False" OnRowCreated="GridView_OnRowCreated" 
                    DataKeyNames="Id" onsorting="GridView_OnSort">
                        <Columns>
                            ...
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <ajax:AsyncPostBackTrigger ControlID="CreateButton"/>
                </Triggers>
            </ajax:UpdatePanel>

Theres another button on the page called CreateButton, obviously, that will populate the gridview and make it visible so a user can select from it. Is this possible? Thanks in advance.

Edit: Binding Code to gridview:

    protected void Create_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Number.Text))
            {
                BLL newbll = new BLL();
                Database.DataTable tempTable = newbll.GetItemByPartNumber(Number.Text);

                if (Table.Count != 0)
                {
                DataTable table = tempTable ;

                string[] VID = { "Id" };
                GridviewDiv.Visible = true;
                GridView.DataSource = table;
                GridView.DataKeyNames = VID;
                GridView.DataBind();
            }
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

画▽骨i 2024-07-22 20:28:54

由于更新面板的更新模式设置为“条件”,因此在网格视图上调用 DataBind 后的代码中,您需要对更新面板的名称(在本例中名为 UpdatePanel)调用 Update()。

Since your update panel's update mode is set to Conditional, in your code behind after your call to DataBind on the grid view, you will need to call Update() on the name of your Update Panel (named UpdatePanel in this instance).

固执像三岁 2024-07-22 20:28:54

将 CreateButton 声明为触发器后,您不必显式调用 Update() 来进行刷新

您在哪里声明了 CreateButton ? - 它必须与 UpdatePanel 位于同一“NamingContainer”中才能找到它

您能否将 CreateButton 的声明移至更新面板内。 如果是这样,您不需要显式声明触发器 - 看看这是否会产生影响

Having declared the CreateButton as a trigger you shouldn't have to explicitly call Update() to do the refresh

Where have you declared the CreateButton ? - it must be in the same 'NamingContainer' as the UpdatePanel for it to be found

Can you move the declaration of the CreateButton inside your update panel. If so you do not need to explicitly declare a trigger - see if that makes a difference

对不⑦ 2024-07-22 20:28:54

使用以下内容

<asp:UpdatePanel ID="..." runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">       
    <ContentTemplate>
      <asp:GridView  ....>
      </asp:GridView .....>

    ///buttons ..............whatever

    </ContentTemplate>

Use the following

<asp:UpdatePanel ID="..." runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">       
    <ContentTemplate>
      <asp:GridView  ....>
      </asp:GridView .....>

    ///buttons ..............whatever

    </ContentTemplate>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文