使用 FindControl 设置文本框的文本
我需要能够在运行时将文本框(位于 gridview 行内)文本设置为某个字符串。我以前使用过 FindControl,但无法弄清楚实际设置文本框的值而不仅仅是获取的语法。这是我所拥有的,但无法编译:
((TextBox)e.Row.FindControl("txtPath")).Text = dataMap.GetString("targetPath"));
如果有任何帮助,我将不胜感激,
谢谢
I need to be able to set a textbox's (which is inside a gridview row) text to a certain string in runtime. I have used FindControl before, but can't figure out the syntax for actually setting the value of the textbox rather than just getting. Here's what I have, which doesn't compile:
((TextBox)e.Row.FindControl("txtPath")).Text = dataMap.GetString("targetPath"));
I'd be grateful for any help
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这行得通吗?
编辑:实际上我喜欢这比我原来的帖子更好:
Will this work?
EDIT: Actually I like this is better than my orginal post:
它无法编译的原因是因为看起来 GetString() 函数的末尾有一个额外的右括号。
试试这个:
最好的做法是检查 TextBox 是否不为空,但这不是必需的。
The reason it doesn't compile is because it looks like you have a extra closing bracket on the end of the GetString() function.
Try this:
It is best practice to check that the TextBox is not null, but is not required.