如何通过命令按钮发送多个命令参数?(RowCommand Event)



当一个行命令被调用时,我试图发送多个命令参数:

                <asp:TemplateField HeaderText="Status">
                    <ItemTemplate>
                        <asp:Button ID="btnAct" runat="server" CausesValidation="False" CommandName="Action"
                            Text='De-Activate' CommandArgument='<%# Bind("isActiveYN") + ";" + Bind("employeeid") %>' />                           

                        <asp:Label ID="lblActivate" runat="server" Text='<%# Bind("isActiveYN") %>' Visible='False'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

当我使用多个参数时,它只显示后一半,在这个employeeid中,如果我只指定一个参数,它工作得很好

protected void gvEmp_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string changeactive = null;
        if (e.CommandName == "Action")
        {
            //LinkButton lnkPortal = (LinkButton)sender;
            string isactivestatus = Convert.ToString(e.CommandArgument);
            string[] arg = new string[2];
            arg = isactivestatus.Split(';');
            //lblTest.Text = isavtivestatus.Text;
            string status = Convert.ToString(arg[0]);
            int empid = Convert.ToInt32(arg[1]);
            if (status.ToUpper() == "Y")
            {
                lblTest.Text = isactivestatus + " Will Change to N  " ;
                changeactive = "N";
            }
            else if (arg[0].ToUpper() == "N")
            {
                lblTest.Text = isactivestatus + " Will Change to Y  " ;
                changeactive = "Y";
            }
            DataSet ds = new DataSet("Employees");
            string query = "Update employees set isActiveYN='" + changeactive 
                            + "' where employeeid=" + empid;

            SqlConnection con = new SqlConnection("Password=admin;User ID=admin;Initial Catalog=asptest;Data Source=dbsvr");
            SqlDataAdapter da = new SqlDataAdapter(query, con);
            da.Fill(ds);
            BindGrid();
        }
    }

请指出错误。

Pavitar, try -

<%# Eval("isActiveYN") + ";" + Eval("employeeid") %>

Bind -这是双向绑定,用于将修改后的数据传递到服务器端。ASP不能将一个值从客户端分离到多个服务器属性

最新更新