如何使用Jquery从Sql数据库中提取数据来填充Asp:Dropdownlist [英] How Do I Fill A Asp:Dropdownlist Using Jquery With Data Pulled From Sql Database

查看:59
本文介绍了如何使用Jquery从Sql数据库中提取数据来填充Asp:Dropdownlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试填写< asp:DropDownList>来自数据库的数据,但我似乎无法让它工作,因为没有显示。我不确定我是否完全忽略了这一点,或者我只是没有正确地将下拉列表与数据联系起来。





To事情清楚我在一个页面上有一个div,它显示一个包含一些数据的表和带有两个按钮的下拉列表。填充表格的数据来自一个隐秘的页面,看不见我只用它来创建表格然后在页面上

Hi Everyone,

I am trying to fill an <asp:DropDownList> with data from a database but i cant seem to get it to work as nothing shows. I am not sure if i am completely missing the point or whther i am just not linking the dropdown with the data correctly.


To make things clear i have a div on one page which shows a table with some data and the dropdownlist with two buttons. The data to fill the table comes from a stealth page that is not seen i only use it to create the table and then on the page the

所在我用JavaScript来调用表格数据。(对不起,如果这不是有意义)我需要使用相同的方法下拉或甚至不同的方式来填充下拉列表但我似乎无法做到这一点。



我的代码。 。



这是我在搜索页面上的div

is located i use JavaScript to call the table data.(sorry if this doesn't make sense) and i need to use the same method for the dropdown or even a diferent way to populate the dropdown but i cant seem to do this.

My Code..

yhis is my div located on my search page
<div id="dUserSystems" runat="server" >
        <u>Systems user has access to</u><br />
            <div id="dUserData"></div>
        <br /><br />
    <div id="ddlSysData" runat="server" >
         <u>Add new system to users account</u><br />

        <asp:DropDownList ID="sysDDL" runat="server"></asp:DropDownList>

    </div>
        <br /><br />
        <input type="button" id="butAdd" value="Add" runat="server" style="font-family: Verdana,Tahoma,Arial; float: left;"/>&nbsp;&nbsp;
        <input type="button" onclick="butClose()" value="Close" />
</div>





以下是我的服务器端代码,为来自不同页面的表格





below is my server side code creating the data for the table from a different page

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        'Add session check here

        If Request.QueryString("userid") <> "" Then

            Dim dsResults As New DataSet
            Dim dt As DataTableReader

            dsResults = GetUserName.systemData(Request.QueryString("userid").ToString)
            dt = dsResults.CreateDataReader

            Dim dv As New HtmlGenericControl("div")
            dv.ID = "sysData"

            Dim tb As New Table
            Dim tr As New TableRow
            Dim tc As New TableCell
            Dim lb As New Label
            Dim iCount As Integer = 1

            If dt.HasRows = True Then

                tr = New TableRow
                tr.CssClass = "tabHeader"
                tc = New TableCell
                tc.CssClass = "tabCell"
                lb = New Label

                lb.Text = "System Name"
                tc.Controls.Add(lb)
                tr.Controls.Add(tc)
                tb.Controls.Add(tr)

                tr.CssClass = "tabHeader"
                tc = New TableCell
                tc.CssClass = "tabCell"
                lb = New Label

                lb.Text = "Date Added"
                tc.Controls.Add(lb)
                tr.Controls.Add(tc)
                tb.Controls.Add(tr)


                tr.CssClass = "tabHeader"
                tc = New TableCell
                tc.CssClass = "tabCell"
                lb = New Label

                lb.Text = "Added By"
                tc.Controls.Add(lb)
                tr.Controls.Add(tc)
                tb.Controls.Add(tr)

                Do While dt.Read

                    tr = New TableRow

                    If iCount = 1 Then
                        tr.CssClass = "rowStyle3"
                        iCount = 0
                    Else
                        tr.CssClass = "rowStyle4"
                        iCount = 1
                    End If

                    'tr = New TableRow
                    tc = New TableCell
                    tc.CssClass = "rowCell2"
                    lb = New Label

                    lb.Text = dt.Item("description").ToString()
                    tc.Controls.Add(lb)
                    tr.Controls.Add(tc)
                    tb.Controls.Add(tr)

                    'tr = New TableRow
                    tc = New TableCell
                    tc.CssClass = "rowCell2"
                    lb = New Label


                    lb.Text = dt.Item("date_added").ToString()
                    tc.Controls.Add(lb)
                    tr.Controls.Add(tc)
                    tb.Controls.Add(tr)

                    'tr = New TableRow
                    tc = New TableCell
                    tc.CssClass = "rowCell2"
                    lb = New Label

                    lb.Text = dt.Item("added_by").ToString()
                    tc.Controls.Add(lb)
                    tr.Controls.Add(tc)
                    tb.Controls.Add(tr)
                Loop
                dt.Close()
                dsResults.Dispose()


                dv.Controls.Add(tb)
                sysData.Controls.Add(dv)
            Else
                Response.Write("No Systems Located for User")
            End If


        End If





我尝试用下面的数据创建一个表格用于下拉但我没有运气。



如果我有困惑或者您需要更多信息请告诉我。



谢谢



I have tried creating a table with the data as above for the drop down but i have had no luck.

If i have confused or you need more info please let me know.

Thank You

推荐答案

非常基本和简单:使用jQuery在ASP.NET中绑定下拉列表AJAX [ ^ ]



问候..
Very basic and simple : Bind Dropdownlist in ASP.NET using jQuery AJAX[^]

Regards..


如果你使用的是ASP.NET,你可以使用一个代码隐藏文件中的服务器端语言并获取来自数据库的数据,然后将其绑定到一个控件easilly。举个例子查看下面的链接

ASP.Net中的DataBinding DropDownList标签和文本框控件 [ ^ ]
If you are using ASP.NET you can use one of server side language in your code behind file and fetch the data from database and then bind it to a control easilly. for some example check below link
DataBinding DropDownList Label and Textbox Controls in ASP.Net[^]


这篇关于如何使用Jquery从Sql数据库中提取数据来填充Asp:Dropdownlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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