点击WindowField列报未定义错误

May 4, 2011 at 11:36 AM

ExtAspNet V2.3.4

Grid的AutoPostBack=true,并且含有WindowField列,点击windowfield列弹出window1,window1关闭后重新绑定grid的数据,如果重新绑定的数据发生了变化,则再一次点击windowfield列时会报x?未定义错误.

aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="grid_autopostback.aspx.cs"
    Inherits="ExtAspNet.Examples.data.grid_autopostback" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <ext:PageManager ID="PageManager1" runat="server" />
    <ext:Grid ID="Grid1" Title="Grid1" ShowBorder="true" ShowHeader="true" Width="900px"
        AutoHeight="true" runat="server" EnableCheckBoxSelect="true" DataKeyNames="Id,Year,MyText"
        OnRowDataBound="Grid1_RowDataBound" EnableRowNumber="True" AutoPostBack="true"
        OnRowClick="Grid1_RowClick">
        <Columns>
           <ext:WindowField  HeaderText="MyText" DataTextField="MyText" WindowID="Window1" Title="test" DataIFrameUrlFields="MyText"
                        DataIFrameUrlFormatString="testwindow.aspx?ID={0}" Width="150px" ColumnId="Part" />

            <ext:BoundField DataTooltipField="MyText" Width="200px" DataField="MyText" DataFormatString="{0}"
                HeaderText="MyText" ExpandUnusedSpace="True" />
            <ext:BoundField ColumnID="column1" Width="100px" DataField="MyValue" HeaderText="MyValue" />
            <ext:BoundField Width="60px" DataField="Year" HeaderText="Year" />
            <ext:CheckBoxField DataTooltipField="MyText" Width="60px" RenderAsStaticField="true"
                DataField="MyCheckBox" HeaderText="CheckBox" />
            <ext:HyperLinkField DataTooltipField="MyText" Width="200px" HeaderText="HyperLink"
                DataTextField="MyText" DataTextFormatString="{0}" DataNavigateUrlFields="Id,MyValue"
                DataNavigateUrlFormatString="http://www.google.com/search?q=ExtAspNet+{0}+{1}"
                Target="_blank" NavigateUrl="~/alert.aspx" Text="HyperLink" />
            <ext:TemplateField HeaderText="TemplateField">
                <ItemTemplate>
                    <%-- Container.DataItem should be System.Data.DataRowView or Custom Class --%>
                    <%# GetMyValue(DataBinder.Eval(Container.DataItem, "MyValue")) %>
                </ItemTemplate>
            </ext:TemplateField>
            <ext:ImageField DataTooltipField="MyText" Width="60px" DataImageUrlField="MyValue"
                DataImageUrlFormatString="~/images/16/{0}.png" HeaderText="Image"></ext:ImageField>
        </Columns>
    </ext:Grid>
    <br />

    <ext:Window ID="Window1" runat="server" Height="380px" IsModal="true" Hidden ="true" Title="test"
        Target="Parent" EnableIFrame="true" IFrameUrl="about:blank" Width="400px" OnClose="Window_Close">
    </ext:Window>
    </form>
</body>
</html>

C#:

namespace ExtAspNet.Examples.data
{
    public partial class grid_autopostback : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        protected void Window_Close(object sender, WindowCloseEventArgs e)
        {
            DataTable table = GetDataTable();
            DataRow row = table.NewRow();
            row[0] = 10001;
            row[1] = "Nancy-add";
            row[2] = "1";
            row[3] = "2008";
            row[4] = true;
            table.Rows.Add(row);
            Grid1.DataSource = table;
            Grid1.DataBind();

        }
        #region LoadData
        private void LoadData()
        {
            DataTable table = GetDataTable();

            Grid1.DataSource = table;
            Grid1.DataBind();
        }

        #endregion


        #region GetMyValue

        protected string GetMyValue(object value)
        {
            return (Convert.ToInt32(value) * 100).ToString();
        }

        #endregion

        #region Event Grid

        protected void Grid1_RowDataBound(object sender, ExtAspNet.GridRowEventArgs e)
        {
            // e.DataItem  -> System.Data.DataRowView or custom class.
            // e.RowIndex -> Current row index.
            // e.Values -> Rendered html for each column of this row.

            DataRowView row = e.DataItem as DataRowView;
            if (row != null)
            {
                e.Values[1] = String.Format("Bound - {0}", row["MyValue"]);
            }
        }


        protected void Grid1_RowClick(object sender, ExtAspNet.GridRowClickEventArgs e)
        {
            Alert.ShowInParent(String.Format("You Click Row: {0}", e.RowIndex + 1));
        }

       

        #endregion

    }
}