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

时间:2011-08-04 09:26:56

标签: asp.net rowcommand commandargument

我正在尝试在调用rowcommand时发送多个命令参数:

                <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();
        }
    }

请指出错误。我已经尝试过调试,但无法判断出错了。

1 个答案:

答案 0 :(得分:9)

Pavitar,试试 -

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

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