本文介绍了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

推荐答案

While dr.Read()
                TB1.Text &= dr.Item("P_id").ToString
                TB2.Text &= dr.Item("P_Name").ToString
End While


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

08-30 06:22