本文介绍了asp.net gridview itemtemplate从codebehind文件添加找不到textchanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从.cs文件创建了itemtemplate并动态添加了文本框。但现在我找不到它的textchanged事件。



i have created itemtemplate from .cs file and add textbox to it dynamically.but now i can't find it's textchanged event.

public delegate void TextChangedMethod(object sender, EventArgs e);
public class ItemTemplate : ITemplate
{
    private string p;
    private object p_2;
    private TextChangedMethod delegateMethod;

    public ItemTemplate(string p, object p_2, TextChangedMethod delegateMethod)
    {
        // TODO: Complete member initialization
        this.p = p;
        this.p_2 = p_2;
        this.delegateMethod = delegateMethod;
    }

    public void InstantiateIn(Control container)
    {
        TextBox tb = new TextBox();

        //tb.TabIndex = ((GridViewRow)Container).RowIndex;
        tb.DataBinding += new EventHandler(this.OnDataBinding);
        tb.AutoPostBack = true;
      //  tb.TextChanged += new EventHandler(this.delegateMethod);
        tb.TextChanged += new EventHandler(this.rbAnswer_TextChanged);
        //tb.ID = p;
        tb.Width = 20;
        container.Controls.Add(tb);
    }

    public void OnDataBinding(object sender, EventArgs e)
    {
        TextBox rdAnswer = (TextBox)sender;
        GridViewRow container = (GridViewRow)rdAnswer.NamingContainer;
        rdAnswer.Text = DataBinder.Eval(container.DataItem, DateTime.Now.Day.ToString()).ToString();
    }
    public void rbAnswer_TextChanged(object sender, EventArgs e)
    {
        TextBox txt = (TextBox)sender;
        txt.Text = "2";
    }
}
}

i have call these method from gridview databinding event....
TemplateField bf = new TemplateField();
                bf.HeaderText = i.ToString();
                ItemTemplate objTemplate = new ItemTemplate("rdAnswer", dt, txt_TextChanged);
                bf.ItemTemplate = objTemplate;
                GridView1.Columns.Add(bf);





但它不起作用。

textbox在浏览器上显示,但是当我执行textchanged事件文本框将消失...

请给我解决方案。



but it's not working.
textbox display on browser but when i perform textchanged event textbox will disappear...
please give me solution.

推荐答案


这篇关于asp.net gridview itemtemplate从codebehind文件添加找不到textchanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 10:05