大家来探讨探讨:在GridView里用了一列模版列
 <asp:TemplateField>
                                <ItemTemplate>                                
                                    <asp:ImageButton ID="Imbrowse" runat="server" CommandName="showMsg" CommandArgument='<%# Eval("Tid") %>' ImageUrl="link_image/show.gif" />                                    
                                    <asp:LinkButton ID="lbh" runat="server" CommandArgument='<%# Eval("Tid")%>' CommandName="lock"><%#Eval("Ttitle")%></asp:LinkButton><br />
                                    <asp:GridView ID="GridView1" runat="server" ShowHeader="False" AutoGenerateColumns="False">
                                        <Columns>
                                            <asp:BoundField DataField="sid" >
                                                <ItemStyle CssClass="hidden" />
                                                <FooterStyle CssClass="hidden" />
                                            </asp:BoundField>
                                            <asp:HyperLinkField  DataTextField="stitle" DataNavigateUrlFields="Sid" DataNavigateUrlFormatString="ForumMsgBrowse.aspx?fsid={0}"/>
                                        </Columns>
                                    </asp:GridView>
                                </ItemTemplate>
                            </asp:TemplateField>
事件:
在protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)事件中写了
if (e.CommandName == "showMsg")
        {
            string strTid = e.CommandArgument.ToString();
Response.Write(strTid);
}
测试时:报错信息
回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。  
而奇怪的是:
if (e.CommandName == "lock")
        {
            string strTid = e.CommandArgument.ToString();
Response.Write(strTid);
}
运行正确。问题:
imagebutton 事件有问题。linkbutton事件却没问题。
请问怎么回事? 设置enableEventValidation="true" 为false,
imagebutton事件根本不触发,没任何反应。根本不执行
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)事件.请高手指点.

解决方案 »

  1.   

    我试了下没有问题啊,看看是不是别的地方的问题。我的WebCOnfig和页面中都没有设置enableEventValidation
    页面代码基本用你的指示该了下数据列名
    --------------------------- 代码如下 ------------------------------------
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Problem.aspx.cs" Inherits="Problem" %><!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="DataId"
    DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand">
    <Columns>
    <asp:BoundField DataField="DataId" HeaderText="DataId" ReadOnly="True" SortExpression="DataId" />
    <asp:BoundField DataField="UnitId" HeaderText="UnitId" SortExpression="UnitId" />
    <asp:BoundField DataField="UnitName" HeaderText="UnitName" SortExpression="UnitName" />
    <asp:TemplateField>
    <ItemTemplate>                                
                    <asp:ImageButton ID="Imbrowse" runat="server" CommandName="showMsg" CommandArgument='<%# Eval("UnitName") %>' ImageUrl="~/images/button-hover.bmp"  />                                    
                    <asp:LinkButton ID="lbh" runat="server" CommandArgument='<%# Eval("UnitName")%>' CommandName="lock"><%#Eval("UnitName")%></asp:LinkButton><br />
                    <asp:GridView ID="GridView11" runat="server" ShowHeader="False" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
                        <Columns>
                            <asp:BoundField DataField="DataId" >
                                <ItemStyle CssClass="hidden" />
                                <FooterStyle CssClass="hidden" />
                            </asp:BoundField>
                            <asp:HyperLinkField  DataTextField="UnitName" DataNavigateUrlFields="DataId" DataNavigateUrlFormatString="ForumMsgBrowse.aspx?fsid={0}"/>
                        </Columns>
                    </asp:GridView>
                </ItemTemplate>
            </asp:TemplateField> </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultDb %>"
    SelectCommand="SELECT * FROM [td_Unit]"></asp:SqlDataSource>
        
        </div>
        </form>
    </body>
    </html>
      

  2.   

    不用模板列是否可以……
    对于你想要的事件参数: CommandArgument='<%# Eval("Tid") %>' 可以在GridView_RowCreated(Object sender, GridViewRowEventArgs e)中设置。<asp:gridview id="CustomersGridView" 
                  datasourceid="CustomersSource"
                  allowpaging="true" 
                  autogeneratecolumns="false"
                  onrowcommand="CustomersGridView_RowCommand"
                  onrowcreated="CustomersGridView_RowCreated"  
                  runat="server">
                 
                  <columns>
                    <asp:buttonfield buttontype="Link" 
                      commandname="CustomerAdd" 
                      text="Add"/>
                    <asp:boundfield datafield="CustomerID" 
                      headertext="Customer ID"/>
                    <asp:boundfield datafield="CompanyName" 
                      headertext="Company Name"/> 
                    <asp:boundfield datafield="City" 
                      headertext="City"/>         
                  </columns>
                </asp:gridview>
      

  3.   

    还是自己解决了.相信自己,怀疑自己.确定自己.
    偶然的机会看到这篇文章中的一句话.让问题从此结束.
    http://dev.poptool.net/wangluo/asp.net/shujuku/11781.html
      

  4.   

    感谢
    dajianshi(拔剑四顾心茫然) ,xavier_lee(我自横刀哈哈笑!) 的回复.