GridView编辑 [英] GridView Edit

查看:72
本文介绍了GridView编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我正在开发asp.net项目.在这里单击
中的文本框 gridview编辑,显示错误消息.
错误消息为

无效的回发或回调参数.使用配置中的<%pages enableEventValidation ="true"%>或页面中的<%@ Page EnableEventValidation ="true"%>启用事件验证.出于安全目的,此功能验证回发或回调事件的参数源自最初呈现它们的服务器控件.如果数据有效且预期,请使用ClientScriptManager.RegisterForEventValidation方法以注册回发或回调数据以进行验证."

这里的代码为

Hi i''m developing the asp.net project.here when i''m click the textbox in
gridview edit,display the error message.
The error message as

"Invalid postback or callback argument. Event validation is enabled using <%pages enableEventValidation="true"%> in configuration or <%@ Page EnableEventValidation="true"%> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation"

here the code as

<asp:GridView ID="sview" runat="server" SelectedIndex="0" OnRowDataBound ="Table_DataBound"

                style="font-family: Verdana; font-size: X-Small; font-weight: bold; top: 13px; left: 1px; position: absolute; height: 20px; width: 646px; border: 1px Solid Black"

                 OnRowEditing ="Table_Edit" OnRowUpdating ="Table_Update" OnRowCancelingEdit ="Table_Cancel">
                <columns>
                <asp:TemplateField  HeaderText="subname" HeaderStyle-HorizontalAlign ="Left" >
                    <edititemtemplate> 
                        <asp:TextBox ID="txtsubname" runat="server" Text='<%# Bind("subname") %>'> 
                    </edititemtemplate> 
                    <footertemplate> 
                        <asp:TextBox ID="txtNewName" runat="server" > 
                    </footertemplate> 
                    <itemtemplate> 
                        <%# Eval("subname") %>
                    </itemtemplate> 
                
                 <asp:TemplateField HeaderText="sname" HeaderStyle-HorizontalAlign="Left"> 
                    <edititemtemplate> 
                        <asp:DropDownList ID="cmbgname" runat="server" DataTextField="Typename" DataValueField="Id">  
                    </edititemtemplate> 
                    <itemtemplate> 
                        <%# Eval("gname") %>
                    </itemtemplate> 
                    <footertemplate> 
                        <asp:DropDownList ID="cmbgname" runat="server" DataTextField="Typename" DataValueField="Id">  
                    </footertemplate> 
             
                    <asp:CommandField SelectText="" ShowSelectButton="True" />
                    <asp:CommandField CancelText="" EditText="" ShowEditButton="True" 

                        UpdateText="" />
                </columns>
                <SelectedRowStyle BackColor="#5691FE" />
                <HeaderStyle BackColor="#D6BBBA" HorizontalAlign="Left" />







protected void Table_Edit(object sender, object e)
{
    GridViewEditEventArgs ex = new GridViewEditEventArgs(sview.SelectedIndex);
    sview.EditIndex = ex.NewEditIndex;
    BindData();
}
protected void Table_Update(object sender, object e)
{
    DataTable dt = (DataTable)Session["ATable"];
    GridViewRow row = sview.Rows[sview.EditIndex];
    if (row.Cells[6].Text.Equals("Y"))
    {
        dt.Rows[row.DataItemIndex]["subname"] = ((TextBox)(row.Cells[2].FindControl (""))).Text;
        dt.Rows[row.DataItemIndex]["gname"] = ((DropDownList)(row.Cells[4].FindControl(""))).SelectedValue;
    }
    sview.EditIndex = -1;
    DataBind();
}
protected void Table_Cancel(object sender, object e)
{
    sview.EditIndex = -1;
    DataBind();
}



[edit]添加了代码块以保留格式-OriginalGriff [/edit]



[edit]Code blocks added to preserve formatting - OriginalGriff[/edit]

推荐答案

错误明确指出:"使用<%pages启用了事件验证在配置中启用enableEventValidation ="true"%>或在页面中<%@页面EnableEventValidation ="true"%> ,只需将页面的enableEventValidation 设置为false即可.
As error clearly specifies: "Event validation is enabled using <%pages enableEventValidation="true"%> in configuration or <%@ Page EnableEventValidation="true"%> in a page", just set enableEventValidation to false for the page and it should be good to go.


这篇关于GridView编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆