ASP.NET填充一个列表框没有回传 [英] ASP.NET Populate a listbox without a postback

查看:187
本文介绍了ASP.NET填充一个列表框没有回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的aspx页面有一个文本框,和的LinkBut​​ton列表框。

I have a simple aspx page with a textbox, linkbutton and listbox.

列表框是要在一个SQL数据库值填充从存储过程。

The listbox is to be populated with values from a stored procedure in a SQL database.

我想要做什么,不知何故,就是当用户点击的LinkBut​​ton来填充这些变量列表框。理想情况下,我想这样做没有回发。

What I'd like to do, somehow, is to populate the listbox with those variables when the user clicks the linkbutton. Ideally, I'd like to do this WITHOUT a postback.

请问有什么办法可以完成此?

Is there any way this can be accomplished?

谢谢,

杰森

推荐答案

我嘲笑一起来为你真的很快。

I mocked one up for you really quickly.

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<div>


    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>
            <br />
            <asp:ListBox ID="ListBox1" runat="server" DataTextField="yourdesiredcolumnamegoeshere"></asp:ListBox>
        </ContentTemplate>
    </asp:UpdatePanel>

</div>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="Data Source=;Initial Catalog=;User ID=;password=" 
    ProviderName="System.Data.SqlClient" 
    SelectCommand="SELECT [yourdesiredcolumnamegoeshere] FROM [yourtablenamegoeshere]">
</asp:SqlDataSource>
</form>

在code背后:

On the code behind:

protected void LinkButton1_Click(object sender, EventArgs e)
{
    ListBox1.DataSource = SqlDataSource2;
    ListBox1.DataBind();
}

当然,你会在SqlDataSource更改为您的存储过程,但是当你单击该按钮,它将填充该列表而不回发。让我知道你需要什么。

Of course you would change the SqlDataSource to your stored proc, but when you clicked the button, it would populate that list without a postback. Let me know if you need anything else.

-JJ

这篇关于ASP.NET填充一个列表框没有回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆