DropdownList和文本框 [英] DropdownList and textboxes

查看:122
本文介绍了DropdownList和文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好plz帮我纠正这个代码....



这段代码只显示texbox中的第一个结果...如何获得休息plz帮助。 ..



受保护的子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load

cn.Open( )

bindDp()

cn.Close()

End Sub

Public Sub bindDp()



cmd.Connection = cn

cmd.CommandText =Select * From DP_Table

Dim da As New SqlDataAdapter (cmd)

Dim dt As New DataTable()

da.Fill(dt)

DropDownList1.DataSource = dt

DropDownList1.DataTextField =(P_id)。ToString()

DropDownList1.DataValueField =(P_id)。ToString()

DropDownList1.DataBind()

DropDownList1.Items.Insert(0,Select Name)

End Sub



Public Sub txtDp ()

Dim stateTable As New DataTable

stateTable.Clear()

Dim sqlcmd As New Sql命令(选择P_id,P_Name来自DP_Table,其中P_id ='&DropDownList1.SelectedItem.Value&',cn)

dr = cmd.ExecuteReader()

如果dr.HasRows那么

dr.Read()

TB1.Text =(dr.Item(P_id))

TB2。 Text =(dr.Item(P_Name))

结束如果



结束Sub

Hi plz help me to correct this code....

This code is showing just first result in texboxes...how to get rest plz help...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cn.Open()
bindDp()
cn.Close()
End Sub
Public Sub bindDp()

cmd.Connection = cn
cmd.CommandText = "Select * From DP_Table"
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
DropDownList1.DataSource = dt
DropDownList1.DataTextField = ("P_id").ToString()
DropDownList1.DataValueField = ("P_id").ToString()
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, "Select Name")
End Sub

Public Sub txtDp()
Dim stateTable As New DataTable
stateTable.Clear()
Dim sqlcmd As New SqlCommand("select P_id,P_Name From DP_Table Where P_id = '" & DropDownList1.SelectedItem.Value & "'", cn)
dr = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
TB1.Text = (dr.Item("P_id"))
TB2.Text = (dr.Item("P_Name"))
End If

End Sub

推荐答案

不确定你想要实现的目标。如果您的查询返回多个记录,文本框真的是适当的输出控件吗?你有两个文本框,你在这些字段中的一个记录中写了两个字段。在基于ThePhantomUpvoter建议的修复之后,您现在循环遍历所有记录,但您仍然只是每次通过循环输入文本框中当前记录的值。也许你想要这个?:

Not sure what you're trying to achieve. If your query is returning multiple records, is a textbox really the appropriate output control? You've got 2 textboxes, and you're writing two fields from a single record in those fields. After the fix based on ThePhantomUpvoter's suggestion, you're now looping through all your records, but you're still only entering the values for the current record in the textboxes each time through your loop. Perhaps you want this?:
While dr.Read()
                TB1.Text &= dr.Item("P_id").ToString
                TB2.Text &= dr.Item("P_Name").ToString
End While


这篇关于DropdownList和文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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