编辑GridView时点击文本框弹出一个窗口。
我现在的代码如下
<script language="javascript" type="text/javascript">
function aa()
{
   window.showModalDialog("aa.aspx");
}
</script><asp:GridView ID="gvXGJL" runat="server" AutoGenerateColumns="False" PageSize="10"
Width="98%" AllowPaging="True" AllowSorting="True" DataKeyNames="ID" OnRowCancelingEdit="gvXGJL_RowCancelingEdit" OnRowDeleting="gvXGJL_RowDeleting" OnRowEditing="gvXGJL_RowEditing" OnRowUpdating="gvXGJL_RowUpdating"OnRowDataBound="gvXGJL_RowDataBound">
    <Columns>
         <asp:TemplateField HeaderText="维修项目">
              <EditItemTemplate>
                   <asp:TextBox ID="TextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name")%>'Width="95%" ReadOnly="true" onclick="aa()"></asp:TextBox>
              </EditItemTemplate>
              <ItemTemplate>
                   <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
              </ItemTemplate>
         </asp:TemplateField>
    </Columns>
</asp:GridView>
运行之后会有脚本错误:Object expected

解决方案 »

  1.   

    我在RowDataBound这里面写也是不行的!
      

  2.   

    现在改了下代码
    protected void gvXGJL_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    string _jsEdit = "showModalDialog('ChooseMaintenancePriceFrame.aspx?Cateogry=',null,'dialogWidth=650px;dialogHeight=500px;help:no;status:no')";
                    TextBox TextBox1= (TextBox)e.Row.Cells[0].FindControl("TextBox1");
                    if (TextBox1!= null)
                    {
                        //这条OK
                        e.Row.Cells[0].Attributes.Add("onclick", _jsEdit );
                        //这条就不行了
                           e.Row.Cells[0].Attributes.Add("onclick", "aa()");                }
                }
    }
    真是很郁闷!
      

  3.   

    在RowDataBound里面写,好像还需要改那个属性才能生效