Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 试图通过asp:TemplateField将函数式asp:CommandField转换为asp:LinkButton_Asp.net - Fatal编程技术网

Asp.net 试图通过asp:TemplateField将函数式asp:CommandField转换为asp:LinkButton

Asp.net 试图通过asp:TemplateField将函数式asp:CommandField转换为asp:LinkButton,asp.net,Asp.net,我想利用LinkButton与CommandField相比的属性宽度。从单击调用代码隐藏方法时,我收到以下错误消息: CS0123:与委托匹配的“ViewHandler”没有重载 “System.EventHandler” GridView定义: <asp:GridView ID="wc" EmptyDataText="Empty WC table..." runat="server" AutoGenerateColumns="False" GridLines="Horizontal"

我想利用
LinkButton
CommandField
相比的属性宽度。从单击调用代码隐藏方法时,我收到以下错误消息:

CS0123:与委托匹配的“ViewHandler”没有重载 “System.EventHandler”

GridView定义:

<asp:GridView ID="wc" EmptyDataText="Empty WC table..." runat="server" 
AutoGenerateColumns="False" GridLines="Horizontal" DataKeyNames="WC_ID,PW_ID,R_Qty" 
CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"  
AllowSorting="true" OnSorting="Sorting" AllowPaging="true" PageSize="15" ViewStateMode="Enabled"
OnSelectedIndexChanging="ViewHandler" OnPageIndexChanging="HandlePageIndexChanging" OnRowDataBound="gvRowDataBound"
OnRowEditing="gvRowEditing" OnRowCancelingEdit="gvRowCancelingEdit" OnRowUpdating="gvRowUpdating">
我需要做什么才能使签名与
ViewHandler
方法匹配?我注意到如果我从
GridViewSelectEventArgs
切换到
EventArgs
,过载错误会消失,但是
e.NewSelectedIndex
不存在


谢谢

您的问题是
链接按钮的
OnClick
事件处理程序必须具有以下签名:

protected void LinkButton_Click(Object sender, EventArgs e) 
但你把它定义为

protected void ViewHandler(object sender, GridViewSelectEventArgs e)
但是,显然,您将无法访问e.NewSelectedIndex。您可以做的是将标记更改为(注意
CommandArgument
部分):

注意:

  • Prop1、Prop2等。
    必须从数据源更改为实际的属性名称
  • 上面的代码还没有经过测试,但这就是想法

  • 我确实知道这件事。。。CommandArguments字符串的构建是错误的,但我可以找到答案-谢谢!
    protected void ViewHandler(object sender, GridViewSelectEventArgs e)
        {
            string WC_ID =wc.Rows[e.NewSelectedIndex].Cells[0].Text;
            string PW_ID = wc.Rows[e.NewSelectedIndex].Cells[1].Text;
            string VIN = wc.Rows[e.NewSelectedIndex].Cells[2].Text;
            string PROD = wc.Rows[e.NewSelectedIndex].Cells[3].Text;
            string W = wc.Rows[e.NewSelectedIndex].Cells[4].Text;
            string SIZE = wc.Rows[e.NewSelectedIndex].Cells[5].Text;
            e.Cancel = true;
            Session.Add(WebConstants.WC_ID, WC_ID);
            Session.Add(WebConstants.PW_ID, PW_ID);
            Session.Add(WebConstants.VIN, VIN);
            Session.Add(WebConstants.PROD, PROD);
            Session.Add(WebConstants.W, W);
            Session.Add(WebConstants.SIZE, SIZE);
            DetailsNavigateMethod.DynamicInvoke();
            HandlePageNavigation(WebConstants.WC_DETAILS, "WC View for WC_PurchaseID-> " + Session[WebConstants.WC_ID].ToString());
        }
    
    protected void LinkButton_Click(Object sender, EventArgs e) 
    
    protected void ViewHandler(object sender, GridViewSelectEventArgs e)
    
    <asp:TemplateField HeaderText="..." ShowHeader="True" ItemStyle-HorizontalAlign="Center"> 
            <ItemTemplate> 
              <asp:LinkButton style="font-size: 0.9em; color: #717171" ID="Details" runat="server" CausesValidation="False" OnClick="ViewHandler" CommandName="ViewHandler" CommandArgument='<%=string.Format("{0},{1},{2},{3}",Eval("Prop1"),Eval("Prop2"),Eval("Prop3"),Eval("Prop4")) %>' Text="..." ToolTip="Click here to see purchase history and notes"></asp:LinkButton> 
            </ItemTemplate> 
        </asp:TemplateField>
    
    protected void LinkButton_Click(Object sender, EventArgs e) 
    {
            string [] values = ((LinkButton)(sender)).CommandArgument.Split(new char[]{','});
            //where  values[0] will have WC_ID, values[1]=PW_ID, etc,
            Session.Add(WebConstants.WC_ID, values[0]);
            Session.Add(WebConstants.PW_ID, values[1]);//etc...
            //Session.Add(WebConstants.VIN, VIN);
            //Session.Add(WebConstants.PROD, PROD);
            //Session.Add(WebConstants.W, W);
            //Session.Add(WebConstants.SIZE, SIZE);
            DetailsNavigateMethod.DynamicInvoke();
            HandlePageNavigation(WebConstants.WC_DETAILS, "WC View for WC_PurchaseID-> " +  Session[WebConstants.WC_ID].ToString());
    }