4

我正在尝试在调用 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();
        }
    }

请指出错误。我尝试过调试,但无法判断出什么问题。

4

1 回答 1

9

帕维塔,试试——

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

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

于 2011-08-04T09:55:30.123 回答