DataView模板类(转载)

ContractedBlock.gif ExpandedBlockStart.gif Code
 1ExpandedBlockStart.gifContractedBlock.gif/**//// <summary>
 2/// 产生模板
 3/// </summary>

 4public class GenericItem : ITemplate
 5ExpandedBlockStart.gifContractedBlock.gif{
 6    private string _column;
 7    private bool _isEditable;
 8    //private bool validate;
 9
10    public GenericItem(string column, bool isEditable)
11ExpandedSubBlockStart.gifContractedSubBlock.gif    {
12        this._column = column;
13        this._isEditable = isEditable;
14    }

15
16    public GenericItem(string column, string controlType)
17ExpandedSubBlockStart.gifContractedSubBlock.gif    {
18        this._column = column;
19    }

20ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
21    /// 实现接口
22    /// </summary>
23    /// <param name="container"></param>

24    public void InstantiateIn(Control container)
25ExpandedSubBlockStart.gifContractedSubBlock.gif    {
26        if (_isEditable)
27ExpandedSubBlockStart.gifContractedSubBlock.gif        {
28            TextBox tb = new TextBox();
29            tb.DataBinding += new EventHandler(this.BindData);
30            container.Controls.Add(tb);
31            tb.ID = _column;
32
33            //禁止数据为空
34            RequiredFieldValidator rfv = new RequiredFieldValidator();
35            rfv.Text = "Please Answer";
36            rfv.ControlToValidate = tb.ID;
37            rfv.Display = ValidatorDisplay.Dynamic;
38
39            rfv.ID = "validate" + tb.ID;
40            container.Controls.Add(rfv);
41        }

42        else
43ExpandedSubBlockStart.gifContractedSubBlock.gif        {
44            Literal l = new Literal();
45            l.DataBinding += new EventHandler(this.BindData);
46            container.Controls.Add(l);
47        }

48    }

49
50ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
51    /// 数据绑定
52    /// </summary>
53    /// <param name="sender"></param>
54    /// <param name="e"></param>

55    public void BindData(object sender, EventArgs e)
56ExpandedSubBlockStart.gifContractedSubBlock.gif    {
57        if (_isEditable)
58ExpandedSubBlockStart.gifContractedSubBlock.gif        {
59            TextBox tb = (TextBox)sender;
60            DataGridItem container = (DataGridItem)tb.NamingContainer;
61            tb.Text = ((DataRowView)container.DataItem)[_column].ToString();
62        }

63        else
64ExpandedSubBlockStart.gifContractedSubBlock.gif        {
65            Literal l = (Literal)sender;
66            DataGridItem container = (DataGridItem)l.NamingContainer;
67            l.Text = ((DataRowView)container.DataItem)[_column].ToString();
68        }

69    }

70}

转载于:https://www.cnblogs.com/ccjnet/archive/2008/11/11/1331166.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值