如何在不复制代码的情况下使DataGrid TemplateColumn ItemTemplate和EditItemTemplate相同? [英] How to make DataGrid TemplateColumn ItemTemplate and EditItemTemplate the same without duplicating code?

查看:61
本文介绍了如何在不复制代码的情况下使DataGrid TemplateColumn ItemTemplate和EditItemTemplate相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有这样的事情:

Currently, I have something like this:

<br /><asp:DataGrid><br />  <asp:TemplateColumn><br />    <ItemTemplate><br />      //some markup that tells us what controls to draw for ItemTemplate<br />    </ItemTemplate><br />    <EditItemTemplate><br />      //same markup as in ItemTemplate which should not be duplicated<br />    </EditItemTemplate><br />  </asp:TemplateColumn><br /></asp:DataGrid><br />



我想知道是否有一种方法(在C#幕后)或标记本身中可以以便我们不必重复标记.我找到了一个用于FormView控件的线程,可以在其中设置FormView.EditItemTemplate = FormView.ItemTemplate,但不幸的是,这不适用于DataGrid TemplateColumn类型.



I was wondering if there was a way (either behind the scenes in C#) or in the markup itself, to make it so that we don''t have to duplicate the markup. There was a thread I found for the FormView control, where we could set FormView.EditItemTemplate = FormView.ItemTemplate, but unfortunately, this is not available for the DataGrid TemplateColumn type.

推荐答案

问候,
我认为您阅读的线程已经为您提供了正确的方法……仅是正确转换模板列的问题,然后将EditItemTemplate property设置为ItemTemplate property ...这是代码:

Greetings,
I think the thread you read already gave you the correct way ... its only a matter of casting the template column correctly then set the EditItemTemplate property to ItemTemplate property ... here is the code:

TemplateField colmun = this.GridView1.Columns[0] as TemplateField;<br />colmun.EditItemTemplate = colmun.ItemTemplate;






这篇关于如何在不复制代码的情况下使DataGrid TemplateColumn ItemTemplate和EditItemTemplate相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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