Asp.net 在下拉列表中,我的DataTextField是00000001,但它在selectedvalue中显示1
在下拉列表中,我的DataTextField是00000001,但它在selectedvalue中显示1Asp.net 在下拉列表中,我的DataTextField是00000001,但它在selectedvalue中显示1,asp.net,vb.net,data-binding,Asp.net,Vb.net,Data Binding,在下拉列表中,我的DataTextField是00000001,但它在selectedvalue中显示1 Sub MerchantDropDown() Dim ds As New DataSet ds = Utilities.spMerchantName1() ddlMerchantDropDownList.DataSource = ds ddlMerchantDropDownList.DataTextField = "Merch
Sub MerchantDropDown()
Dim ds As New DataSet
ds = Utilities.spMerchantName1()
ddlMerchantDropDownList.DataSource = ds
ddlMerchantDropDownList.DataTextField = "MerchantName1"
ddlMerchantDropDownList.DataValueField = "MerchantID"
ddlMerchantDropDownList.DataBind()
ddlMerchantDropDownList.Items.Insert(0, "All Merchant")
End Sub
IIf(ddlMerchantDropDownList.SelectedIndex = 0, "-999", ddlMerchantDropDownList.SelectedValue()))
这是下拉列表的默认行为。从下拉列表中选择值后,可以填充零
ddlMerchantDropDownList.SelectedValue.tostring.padleft(7,"0")
由于您设置了
DataValueField=“MerchantID”
,因此在本例中,SelectedValue
的更多详细信息将是MerchantID
的值
要获取数据文本字段的值
,需要使用:
ddlMerchantDropDownList.SelectedItem.Text
这不是DropDownList的默认行为。这是数据类型的行为。如果你有一个整数,是的,00001是1。但是如果你有一个varchar,00001将是00001。此外,如果OP确实要填充,则它应该是
ddlmercommerditdropdownlist.SelectedValue.ToString().PadLeft(7,“0”)
。