none
自定义GridView控件的问题 RRS feed

  • 问题

  • Hi 我在做一个自定义的GridView控件,我想在GridView的底部添加两个控件并封装起来,我在PrepareControlHierarchy()方法中给GridView添加按钮并注册事件,但是无法触发这个按钮的事件,请问如何解决,代码如下
            protected override void PrepareControlHierarchy()
            {
                base.PrepareControlHierarchy();

                if (this.Controls.Count != 0)
                {
                    //Merge pager style
                    Table table = (Table)this.Controls[0];
                    
                    //Add footer with "Add" & "Delete" button
                    TableRow footer = new TableRow();
                    footer.TableSection = TableRowSection.TableFooter;
                    TableCell footerCell = new TableCell();
                    footerCell.ColumnSpan = this.Columns.Count;
                    footer.Controls.Add(footerCell);
                    Button addButton = new Button();
                    addButton.Text = "Add";
                    addButton.ID = "ButtonAdd";
                    addButton.Click += new EventHandler(ButtonAdd_Click);
                    footerCell.Controls.Add(addButton);
                    Button delButton = new Button();
                    delButton.Text = "Delete";
                    footerCell.Controls.Add(delButton);
                    this.Controls[0].Controls.Add(footer);
                }
            }

            void ButtonAdd_Click(object sender, EventArgs e)
            {
                this.ShowFooter = true;
                this.DataBind();
                this.Rows[0].Visible = false;
            }

    2009年7月9日 6:25

答案

  • 楼主,你好

    如我上面所言,你创建复合控件是在CreateChileControl()方法中进行添加操作。
    如果你想进行style方面的控制。你就得暴露相应的属性供用户进行输入。
    你的Delete事件是要让用户进行操作的,所以你得重写OnBubble事件进行事件提升。
    我给你找了个例子。你参考试试。
    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace MSPress.ServerControls {
        
        [
        DefaultEvent("Logon"),
        DefaultProperty("Name"),
        Designer(typeof(
            MSPress.ServerControls.Design.CompositeControlDesigner))
        ]
        public class CompositeLogin : WebControl, INamingContainer {
    
            private Button _button;
            private TextBox _nameTextBox;
            private Label _nameLabel;
            private TextBox _passwordTextBox;
            private Label _passwordLabel;      
            private RequiredFieldValidator _nameValidator;
            private RequiredFieldValidator _passwordValidator;
    
            private static readonly object EventLogon = new object();
    
            #region Overriden properties 
            public override ControlCollection Controls {
                get {
                    EnsureChildControls();
                    return base.Controls;
                }
            }
            #endregion Overriden properties
    
            #region Properties delegated to child controls 
            [
            Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description("The text to display on the Button")
            ]
            public string ButtonText {
                get {
                    EnsureChildControls();
                    return _button.Text;
                }
                set {
                    EnsureChildControls();
                    _button.Text = value;
                }
            }
    
            [
            Bindable(true),
            Category("Default"),
            DefaultValue(""),
            Description("The user name")
            ]
            public string Name {
                get {
                    EnsureChildControls();
                    return _nameTextBox.Text;
                }
                set {
                    EnsureChildControls();
                    _nameTextBox.Text = value;
                }
            }
    
            [
            Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description(
                "Error message of the validator used for the Name")
            ]
            public string NameErrorMessage {
                get {
                    EnsureChildControls();
                    return _nameValidator.ErrorMessage;
                }
                set {
                    EnsureChildControls();
                    _nameValidator.ErrorMessage = value;
                    _nameValidator.ToolTip = value;
                }
            }
    
            [
            Bindable(true),
            Category("Apperance"),
            DefaultValue(""),
            Description("The text for the name Label")
            ]
            public string NameLabel {
                get {
                    EnsureChildControls();
                    return _nameLabel.Text;
                }
    
                set {
                    EnsureChildControls();
                    _nameLabel.Text = value;
    
                }
            }
    
            [
            Browsable(false),
            DesignerSerializationVisibility(
                DesignerSerializationVisibility.Hidden)
            ]
            public string Password {
                get {
                    EnsureChildControls();
                    return _passwordTextBox.Text;
                }
            }
    
            [
            Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description(
                "Error message of the validator used for the Password")
            ]
            public string PasswordErrorMessage {
                get {
                    EnsureChildControls();
                    return _passwordValidator.ErrorMessage;
                }
                set {
                    EnsureChildControls();
                    _passwordValidator.ErrorMessage = value;
                    _passwordValidator.ToolTip = value;
                }
            }
    
            [
            Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description("The text for the password Label")
            ]
    
            public string PasswordLabel {
                get {
                    EnsureChildControls();
                    return _passwordLabel.Text;
                }
                set {
                    EnsureChildControls();
                    _passwordLabel.Text = value;
    
                }
            }
            #endregion Properties delegated to child controls 
    
            #region Events
            [
            Category("Action"),
            Description("Raised when the user clicks the login button")
            ]
            public event EventHandler Logon {
                add {
                    Events.AddHandler(EventLogon, value);
                }
                remove {
                    Events.RemoveHandler(EventLogon, value);
                }
            }
    
            protected virtual void OnLogon(EventArgs e) { 
                EventHandler logonHandler = 
                    (EventHandler)Events[EventLogon];
                if (logonHandler != null) {
                    logonHandler(this, e);
                }  
            }
            #endregion
    
            #region Event bubbling
            // The use of event bubbling in this scenario is somewhat contrived;
            // we have implemented it mainly for demonstration purposes.
            // In this case you could instead
            // raise the Logon event from an event handler wired to the
            // Click event or to the Command event of the Button control.
            protected override 
                bool OnBubbleEvent(object source, EventArgs e) {   
                bool handled = false;
    
                if (e is CommandEventArgs) {
                    CommandEventArgs ce = (CommandEventArgs)e;
                    if (ce.CommandName == "Logon") {
                        OnLogon(EventArgs.Empty);
                        handled = true;   
                    }  
                }
                return handled;            
            }
            #endregion Event bubbling     
    
            #region Overriden methods 
            protected override void CreateChildControls() {
                Controls.Clear();
    
                _nameLabel = new Label();
                               
                _nameTextBox = new TextBox();
                _nameTextBox.ID = "nameTextBox";
                
                _nameValidator = new RequiredFieldValidator();
                _nameValidator.ID = "validator1";
                _nameValidator.ControlToValidate = _nameTextBox.ID;
                _nameValidator.Text = "*";
                _nameValidator.Display = ValidatorDisplay.Static;
    
                _passwordLabel = new Label();
                
                _passwordTextBox = new TextBox();
                _passwordTextBox.TextMode = TextBoxMode.Password;
                _passwordTextBox.ID = "passwordTextBox";
                
                _passwordValidator = new RequiredFieldValidator();
                _passwordValidator.ID = "validator2";
                _passwordValidator.ControlToValidate = _passwordTextBox.ID;
                _passwordValidator.Text = "*";
                _passwordValidator.Display = ValidatorDisplay.Static;
    
                _button = new Button();
                _button.ID = "button1";
                _button.CommandName = "Logon";
                
                this.Controls.Add(_nameLabel);
                this.Controls.Add(_nameTextBox);
                this.Controls.Add(_nameValidator);
                this.Controls.Add(_passwordLabel);
    
                this.Controls.Add(_passwordTextBox);
                this.Controls.Add(_passwordValidator);
                this.Controls.Add(_button);
            }
    
            protected override void Render(HtmlTextWriter writer) {
                AddAttributesToRender(writer);
    
                writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding,
                    "1", false);
                writer.RenderBeginTag(HtmlTextWriterTag.Table);
    
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _nameLabel.RenderControl(writer);                  
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _nameTextBox.RenderControl(writer);
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _nameValidator.RenderControl(writer);      
                writer.RenderEndTag();  // Td
                writer.RenderEndTag();  // Tr
    
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);          
                _passwordLabel.RenderControl(writer);
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _passwordTextBox.RenderControl(writer);
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _passwordValidator.RenderControl(writer); 
                writer.RenderEndTag();  // Td
                writer.RenderEndTag();  // Tr
    
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
                writer.AddAttribute(HtmlTextWriterAttribute.Align, 
                    "right");
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _button.RenderControl(writer);
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write(" ");
                writer.RenderEndTag();  // Td
                writer.RenderEndTag();  // Tr
    
                writer.RenderEndTag();  // Table
            }
            #endregion Overriden methods 
        }
    }
    
    

    Microsoft Online Community Support
    2009年7月10日 6:04
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI.WebControls;
    using System.Web.UI;
    
    namespace ServerControl1
    {
        public class XGridView : GridView, IPostBackEventHandler
        {
            private string fAddButtonText = "Add";
            private string fDeleteButtonText = "Delete";
            public event EventHandler OnButtonDelete;
    
            public string AddButtonText
            {
                get { return fAddButtonText; }
                set { fAddButtonText = value; }
            }
    
            public string DeleteButtonText
            {
                get { return fDeleteButtonText; }
                set { fDeleteButtonText = value; }
            }
    
            public XGridView()
                : base()
            {
            }
    
            protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
            {
                base.RenderContents(writer);
    
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, "CustomAdd"));
                writer.AddAttribute("SkinId", "ButtonSkin"); // 添加 Attribute
                writer.RenderBeginTag(HtmlTextWriterTag.Button);
                
                writer.Write(this.AddButtonText);
                writer.RenderEndTag();
    
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, "CustomDelete"));
                writer.RenderBeginTag(HtmlTextWriterTag.Button);
                writer.Write(this.DeleteButtonText);
                writer.RenderEndTag();
            }
    
            void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
            {
                if (eventArgument == "CustomAdd")
                {
                    Context.Response.Write("CustomAdd");
                }
                else if (eventArgument == "CustomDelete")
                {
                    if (this.OnButtonDelete != null)
                        this.OnButtonDelete(this, null);
                }
            }
        }
    }
    

    知识改变命运,奋斗成就人生!
    2009年7月10日 6:18
    版主

全部回复

  • GridView 有脚脚,你可以利用页脚显示这个控件,在 ItemDataBound 事件中,判断是否为页脚,然后将控件加入到页脚中去
    知识改变命运,奋斗成就人生!
    2009年7月9日 7:40
    版主
  • GridView 的Foorter row另有用处
    2009年7月9日 9:52
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI.WebControls;
    using System.Web.UI;
    
    namespace ServerControl1
    {
        public class XGridView : GridView, IPostBackEventHandler
        {
            private string fAddButtonText = "Add";
            private string fDeleteButtonText = "Delete";
    
            public string AddButtonText
            {
                get { return fAddButtonText; }
                set { fAddButtonText = value; }
            }
    
            public string DeleteButtonText
            {
                get { return fDeleteButtonText; }
                set { fDeleteButtonText = value; }
            }
    
            public XGridView()
                : base()
            {
            }
    
            protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
            {
                base.RenderContents(writer);
    
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, "CustomAdd"));
                writer.RenderBeginTag(HtmlTextWriterTag.Button);
                writer.Write(this.AddButtonText);
                writer.RenderEndTag();
    
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, "CustomDelete"));
                writer.RenderBeginTag(HtmlTextWriterTag.Button);
                writer.Write(this.DeleteButtonText);
                writer.RenderEndTag();
            }
    
            void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
            {
                if (eventArgument == "CustomAdd")
                    Context.Response.Write("CustomAdd");
                else if (eventArgument == "CustomDelete")
                    Context.Response.Write("CustomDelete");
            }
        }
    }
    


    知识改变命运,奋斗成就人生!
    2009年7月9日 11:06
    版主
  • 楼主,你好

    你应该创建的是一个复合控件吧。创建自定义的GridView时创建控件的层次结构时是在这个CreateControlHierarchy()方法中创建。
    下面建议仅供参考.

    而且如果你想让用户来处理ButtonAdd_Click逻辑,你必须进行事件提升,即冒泡,将该事件提升到类似的顶层触发处理。这时就必须重写OnBubbleEvent。
    protected override 
                bool OnBubbleEvent(object source, EventArgs e) {   
                bool handled = false;
    
                if (e is CommandEventArgs) {
                    CommandEventArgs ce = (CommandEventArgs)e;
                    if (ce.CommandName == "Logon") {
                        OnLogon(EventArgs.Empty);
                        handled = true;   
                    }  
                }
                return handled;            
            }
    
    

    Microsoft Online Community Support
    2009年7月10日 2:46
  • 这样生成的按钮可以用Skin去控制显示样式吗,似乎不起作用
    2009年7月10日 5:24
  • 你好,你需要自己在 Render 的时候去输出它的SkinId
    知识改变命运,奋斗成就人生!
    2009年7月10日 5:25
    版主
  • 我在这个复合控件中添加两个按钮,其中Add按钮的事件我要自己处理掉,Delete按钮的事件我是希望开放给用户

    2009年7月10日 5:49
  • 一个道理,你只需要在控件中,公开一个事件就行
    知识改变命运,奋斗成就人生!
    2009年7月10日 5:53
    版主
  • 不是很明白,您可以帮我写一下这两个声明么,另外render 控件的skinID怎么写
    2009年7月10日 6:02
  • 楼主,你好

    如我上面所言,你创建复合控件是在CreateChileControl()方法中进行添加操作。
    如果你想进行style方面的控制。你就得暴露相应的属性供用户进行输入。
    你的Delete事件是要让用户进行操作的,所以你得重写OnBubble事件进行事件提升。
    我给你找了个例子。你参考试试。
    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace MSPress.ServerControls {
        
        [
        DefaultEvent("Logon"),
        DefaultProperty("Name"),
        Designer(typeof(
            MSPress.ServerControls.Design.CompositeControlDesigner))
        ]
        public class CompositeLogin : WebControl, INamingContainer {
    
            private Button _button;
            private TextBox _nameTextBox;
            private Label _nameLabel;
            private TextBox _passwordTextBox;
            private Label _passwordLabel;      
            private RequiredFieldValidator _nameValidator;
            private RequiredFieldValidator _passwordValidator;
    
            private static readonly object EventLogon = new object();
    
            #region Overriden properties 
            public override ControlCollection Controls {
                get {
                    EnsureChildControls();
                    return base.Controls;
                }
            }
            #endregion Overriden properties
    
            #region Properties delegated to child controls 
            [
            Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description("The text to display on the Button")
            ]
            public string ButtonText {
                get {
                    EnsureChildControls();
                    return _button.Text;
                }
                set {
                    EnsureChildControls();
                    _button.Text = value;
                }
            }
    
            [
            Bindable(true),
            Category("Default"),
            DefaultValue(""),
            Description("The user name")
            ]
            public string Name {
                get {
                    EnsureChildControls();
                    return _nameTextBox.Text;
                }
                set {
                    EnsureChildControls();
                    _nameTextBox.Text = value;
                }
            }
    
            [
            Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description(
                "Error message of the validator used for the Name")
            ]
            public string NameErrorMessage {
                get {
                    EnsureChildControls();
                    return _nameValidator.ErrorMessage;
                }
                set {
                    EnsureChildControls();
                    _nameValidator.ErrorMessage = value;
                    _nameValidator.ToolTip = value;
                }
            }
    
            [
            Bindable(true),
            Category("Apperance"),
            DefaultValue(""),
            Description("The text for the name Label")
            ]
            public string NameLabel {
                get {
                    EnsureChildControls();
                    return _nameLabel.Text;
                }
    
                set {
                    EnsureChildControls();
                    _nameLabel.Text = value;
    
                }
            }
    
            [
            Browsable(false),
            DesignerSerializationVisibility(
                DesignerSerializationVisibility.Hidden)
            ]
            public string Password {
                get {
                    EnsureChildControls();
                    return _passwordTextBox.Text;
                }
            }
    
            [
            Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description(
                "Error message of the validator used for the Password")
            ]
            public string PasswordErrorMessage {
                get {
                    EnsureChildControls();
                    return _passwordValidator.ErrorMessage;
                }
                set {
                    EnsureChildControls();
                    _passwordValidator.ErrorMessage = value;
                    _passwordValidator.ToolTip = value;
                }
            }
    
            [
            Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description("The text for the password Label")
            ]
    
            public string PasswordLabel {
                get {
                    EnsureChildControls();
                    return _passwordLabel.Text;
                }
                set {
                    EnsureChildControls();
                    _passwordLabel.Text = value;
    
                }
            }
            #endregion Properties delegated to child controls 
    
            #region Events
            [
            Category("Action"),
            Description("Raised when the user clicks the login button")
            ]
            public event EventHandler Logon {
                add {
                    Events.AddHandler(EventLogon, value);
                }
                remove {
                    Events.RemoveHandler(EventLogon, value);
                }
            }
    
            protected virtual void OnLogon(EventArgs e) { 
                EventHandler logonHandler = 
                    (EventHandler)Events[EventLogon];
                if (logonHandler != null) {
                    logonHandler(this, e);
                }  
            }
            #endregion
    
            #region Event bubbling
            // The use of event bubbling in this scenario is somewhat contrived;
            // we have implemented it mainly for demonstration purposes.
            // In this case you could instead
            // raise the Logon event from an event handler wired to the
            // Click event or to the Command event of the Button control.
            protected override 
                bool OnBubbleEvent(object source, EventArgs e) {   
                bool handled = false;
    
                if (e is CommandEventArgs) {
                    CommandEventArgs ce = (CommandEventArgs)e;
                    if (ce.CommandName == "Logon") {
                        OnLogon(EventArgs.Empty);
                        handled = true;   
                    }  
                }
                return handled;            
            }
            #endregion Event bubbling     
    
            #region Overriden methods 
            protected override void CreateChildControls() {
                Controls.Clear();
    
                _nameLabel = new Label();
                               
                _nameTextBox = new TextBox();
                _nameTextBox.ID = "nameTextBox";
                
                _nameValidator = new RequiredFieldValidator();
                _nameValidator.ID = "validator1";
                _nameValidator.ControlToValidate = _nameTextBox.ID;
                _nameValidator.Text = "*";
                _nameValidator.Display = ValidatorDisplay.Static;
    
                _passwordLabel = new Label();
                
                _passwordTextBox = new TextBox();
                _passwordTextBox.TextMode = TextBoxMode.Password;
                _passwordTextBox.ID = "passwordTextBox";
                
                _passwordValidator = new RequiredFieldValidator();
                _passwordValidator.ID = "validator2";
                _passwordValidator.ControlToValidate = _passwordTextBox.ID;
                _passwordValidator.Text = "*";
                _passwordValidator.Display = ValidatorDisplay.Static;
    
                _button = new Button();
                _button.ID = "button1";
                _button.CommandName = "Logon";
                
                this.Controls.Add(_nameLabel);
                this.Controls.Add(_nameTextBox);
                this.Controls.Add(_nameValidator);
                this.Controls.Add(_passwordLabel);
    
                this.Controls.Add(_passwordTextBox);
                this.Controls.Add(_passwordValidator);
                this.Controls.Add(_button);
            }
    
            protected override void Render(HtmlTextWriter writer) {
                AddAttributesToRender(writer);
    
                writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding,
                    "1", false);
                writer.RenderBeginTag(HtmlTextWriterTag.Table);
    
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _nameLabel.RenderControl(writer);                  
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _nameTextBox.RenderControl(writer);
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _nameValidator.RenderControl(writer);      
                writer.RenderEndTag();  // Td
                writer.RenderEndTag();  // Tr
    
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);          
                _passwordLabel.RenderControl(writer);
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _passwordTextBox.RenderControl(writer);
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _passwordValidator.RenderControl(writer); 
                writer.RenderEndTag();  // Td
                writer.RenderEndTag();  // Tr
    
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
                writer.AddAttribute(HtmlTextWriterAttribute.Align, 
                    "right");
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                _button.RenderControl(writer);
                writer.RenderEndTag();  // Td
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write(" ");
                writer.RenderEndTag();  // Td
                writer.RenderEndTag();  // Tr
    
                writer.RenderEndTag();  // Table
            }
            #endregion Overriden methods 
        }
    }
    
    

    Microsoft Online Community Support
    2009年7月10日 6:04
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI.WebControls;
    using System.Web.UI;
    
    namespace ServerControl1
    {
        public class XGridView : GridView, IPostBackEventHandler
        {
            private string fAddButtonText = "Add";
            private string fDeleteButtonText = "Delete";
            public event EventHandler OnButtonDelete;
    
            public string AddButtonText
            {
                get { return fAddButtonText; }
                set { fAddButtonText = value; }
            }
    
            public string DeleteButtonText
            {
                get { return fDeleteButtonText; }
                set { fDeleteButtonText = value; }
            }
    
            public XGridView()
                : base()
            {
            }
    
            protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
            {
                base.RenderContents(writer);
    
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, "CustomAdd"));
                writer.AddAttribute("SkinId", "ButtonSkin"); // 添加 Attribute
                writer.RenderBeginTag(HtmlTextWriterTag.Button);
                
                writer.Write(this.AddButtonText);
                writer.RenderEndTag();
    
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(this, "CustomDelete"));
                writer.RenderBeginTag(HtmlTextWriterTag.Button);
                writer.Write(this.DeleteButtonText);
                writer.RenderEndTag();
            }
    
            void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
            {
                if (eventArgument == "CustomAdd")
                {
                    Context.Response.Write("CustomAdd");
                }
                else if (eventArgument == "CustomDelete")
                {
                    if (this.OnButtonDelete != null)
                        this.OnButtonDelete(this, null);
                }
            }
        }
    }
    

    知识改变命运,奋斗成就人生!
    2009年7月10日 6:18
    版主
  • 记得 WebCast 有复合控件课程,有空可以去看看
    知识改变命运,奋斗成就人生!
    2009年7月10日 6:20
    版主
  • 谢谢大家的热心帮助,现在有另外个问题,我点击Add按钮的时候希望将GridView 的FooterRow显示出来,但是指定ShowFooter = true;的话似乎一定要重新绑定才起作用,那我怎样才能在这个GridView里面用原来的DataSource进行重新绑定呢
    2009年7月10日 6:47
  • 一般可用使用Session,Cache 在第一次读取数据的时候将数据保存下来,避免下次读取数据的时候重复读取数据库
    知识改变命运,奋斗成就人生!
    2009年7月10日 6:48
    版主
  • 啊,对啊,我给忘了,光想着GridView自己的属性里去找了,谢谢
    2009年7月10日 7:00