如何动态改变TemplateField的值?
我有一个 GridView,我想在选择它时刷新一行(而不是整个网格)。当网格选定索引更改时,我尝试更改每个 GridView.SelectedRow.Cells 的 Text 属性。它似乎适用于DataField
,但不适用于TemplateField
。对于 TemplateField
我得到了奇怪的结果 - 所选行的值正确更改,但是当我选择另一行时,先前所选行的 TemplateField
值变为空白。简要说明:
1. Nothing selected
--------------------------
id template_field
--------------------------
1 value_1
2 value_2
2. First record selected
--------------------------
id template_field
--------------------------
1 updated_value_1
2 value_2
3. Second record selected
--------------------------
id template_field
--------------------------
1 [blank!]
2 updated_value_2
最终,除了选定的记录外,我最终得到的每条记录都是空白的 template_field
。更改 TemplateField 文本的正确方法是什么?
I have a GridView and I want to refresh a row (not the whole grid) when it gets selected. I tried to change Text
property for each of GridView.SelectedRow.Cells
when Grid selected index changes. It seems to work for DataField
, but not for TemplateField
. For TemplateField
I got strange results - the value for selected row changes properly, but when I select another row, the value of TemplateField
for previously selected row becomes blank. Brief illustration :
1. Nothing selected
--------------------------
id template_field
--------------------------
1 value_1
2 value_2
2. First record selected
--------------------------
id template_field
--------------------------
1 updated_value_1
2 value_2
3. Second record selected
--------------------------
id template_field
--------------------------
1 [blank!]
2 updated_value_2
Eventually, I end up with blank template_field
for each record except selected. What is the proper way to change the text of TemplateField ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 TextBox 控件添加到模板中,并更改它而不是单元格内容。您应该能够通过以下方式获得它:
Try adding a TextBox control to your template, and change it instead of the cell contents. You should be able to get at it via something like this: