How to send multiple command arguments through command button ?(RowCommand Event)

Pavitar picture Pavitar · Aug 4, 2011 · Viewed 14.4k times · Source

I'm Trying to send accross multiple command arguments when a rowcommand is called:

                <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>

How ever when I use more than one argument it shows only the latter half, in this the employeeid .If I specify just a single argument,it works fine.

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

Please point out the mistake.I have tried debugging but couldn't gauge what's wrong.

Answer

vladimir picture vladimir · Aug 4, 2011

Pavitar, try -

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

Bind - it's bidirectional binding that use to passing modified data to serverside. ASP cannot separate one value from client to more then one server property.