问题DropdwonList selectedValue和DataTable列长度 [英] Problem DropdwonList selectedValue and DataTable Column Length

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

问题描述

我有一个名为productid的列,它的长度等于10.我已将该列的maxlength设置为等于10.我将包含该列的DataTable加载到DropDownList中.

I have a column named productid.It has length equal 10.I have set maxlength of the column equal 10.I load DataTable contains this column into DropDownList.I can not select the item using:

ddl.selectedValue=tbl.Rows[0][0].tostring();
//tbl.Rows[0][0].tostring()='PS001'


检查长度后,我得到了ddl的长度:10和tbl.Rows [0] [0] .tostring()的长度:5.SelectValue附加到空白处. 我不能


after checking the length, I get the ddl''s length:10 and tbl.Rows[0][0].tostring()''s lenght:5.SelectValue was attached to the whitespace.
I can''t

ddl.selectedValue.trim()=tbl.Rows[0][0].tostring();


我尝试不设置MaxLength.我仍然得到ddl的长度等于10


I tried not set MaxLength.I still get ddl''s length equal 10
How to fix it?

推荐答案

我不完全理解您的意思,但也许您在错误的一侧使用了trim()!
改用它:
i didn''t understand entirely what you mean but perhaps you are using trim() on the wrong side!
use this instead:
ddl.selectedValue=tbl.Rows[0][0].tostring().Trim();


在加载ddl时,必须提供一个已知值,该值将成为selectedvalue.

设置该值时,您引用的值必须与已知值之一匹配,否则您将无法设置ddl值.
When you load your ddl, you have to provide a known value, which will become the selectedvalue.

When you set the value, the value you reference has to match one of the known values, or else you can''t set the ddl value.
ddl.items.add(new listitem("red", "red"))
ddl.selectedvalue = "red"


我知道这与您的示例无关,但我正在尝试传达selectedvalue的原理

如有疑问,请检查浏览器的浏览器源代码(查看源代码),找到您的ddl,然后查看标记,以获取值的格式


I know it doesn''t relate to your example, but I''m trying to convey the principal of selectedvalue

When in doubt, check the browser browser source (view source), and find your ddl, and look at the tags, for the format of your values

<option value="red">red</option>


这篇关于问题DropdwonList selectedValue和DataTable列长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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