开发者

Displaying a value in a populated combo box

开发者 https://www.devze.com 2023-02-05 15:24 出处:网络
Here is the situation: I have populated a combo box with the names of divisions in my company and it is working fine. I go into edit mode and pull one record out of th开发者_JS百科e data table so I bi

Here is the situation: I have populated a combo box with the names of divisions in my company and it is working fine. I go into edit mode and pull one record out of th开发者_JS百科e data table so I bind all controls on the form with one record. I also populate this combo box with all divisions but want it to display the selected division. While I know how to display correct date in textbox controls, I do not know how to make combo box display only selected data. It displays the first record from the query which populates it. Any suggestions?

Thanks


Not clear if you are using ASP.NET or Windows Form. I am assuming Windows Form at the moment since it has an actual ComboBox control, while ASP.NET only has DropDownList (not counting the AJAX Control Toolkit).

ComboBox has a bunch of Selected... properties, i.e. SelectedIndex, SelectedItem, SelectedValue, SelectedText that you can manipulate (set) to show a certain item on the screen. So you can just do cbDivision.SelectedText = myRecord.Division (assuming Division in myRecord contains the same name as the one bound in the ComboBox.

for reference, see: this


I'm not sure I understood your question correctly. But I think you just want to display the selectedValue in the dropdown list populated from a list of values.

< asp:DropDownList DataTextField="SomeDecsription" DataValueField="SomeValue" ...... />

I apologise if this is not what you were asking for

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号