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

浪子不回头ぞ 提交于 2019-12-12 12:01:21

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6939009/how-to-send-multiple-command-arguments-through-command-button-rowcommand-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!