[Mono-dev] Tiny System.Web.UI.WebControls.DataGrid bug

Sorin Peste neaorin at gmail.com
Sat Jun 16 08:45:32 EDT 2007


Hello,

I've come across a tiny bug in the ASP.NET DataGrid control. I am
testing with Mono 1.2.4 on openSUSE.

Short Description:

When setting DataGrid.EditItemIndex to a nonnegative value in order to
make a row editable, text boxes for all empty string values in the
respective row contain the string ' ' instead of being, well,
empty. The .NET Framework does not have this problem.

Steps to reproduce:

1. Put the two files (.aspx and .cs, see below) into a Mono ASP.NET
application
2. Build your application, then bring up the DataGridNbspTest.aspx page
in your browser
3. Click the 'Edit' link for the first row (the one with the empty
value). The TextBox in the 'value' column will contain the string ' '.

Test Files:

A. DataGridNbspTest.aspx

<%@ Page language="c#" Codebehind="DataGridNbspTest.aspx.cs"
AutoEventWireup="false" Inherits="DataGridNbspBug.DataGridNbspTest" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <body>
        <form id="Form1" method="post" runat="server">
            <asp:DataGrid id="DataGrid1" runat="server"
AutoGenerateColumns="False">
                <Columns>
                    <asp:BoundColumn DataField="Key"
HeaderText="key"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Value"
HeaderText="value"></asp:BoundColumn>
                    <asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
                </Columns>
            </asp:DataGrid>
        </form>
    </body>
</HTML>

B. DataGridNbspTest.aspx.cs

using System;
using System.Collections;
 
namespace DataGridNbspBug
{
    public class DataGridNbspTest : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataGrid DataGrid1;
     
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
                ShowData();
        }
 
        private void ShowData() 
        {
            Hashtable hashtable = new Hashtable();
            hashtable.Add("EmptyValueKey", String.Empty);
            hashtable.Add("SomeKey", "SomeValue");
            DataGrid1.DataSource = hashtable;
            DataBind();
        }
 
        private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            DataGrid1.EditItemIndex = e.Item.ItemIndex;
            ShowData();
        }
 
        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }
         
        private void InitializeComponent()
        {    
            this.DataGrid1.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);

            this.Load += new System.EventHandler(this.Page_Load);
 
        }
        #endregion
    }
}


Sorin



More information about the Mono-devel-list mailing list