gpt4 book ai didi

asp.net - 如何通过命令按钮发送多个命令参数?(RowCommand 事件)

转载 作者:行者123 更新时间:2023-12-02 16:23:51 26 4
gpt4 key购买 nike

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

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

最佳答案

帕维塔,试试 -

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

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

关于asp.net - 如何通过命令按钮发送多个命令参数?(RowCommand 事件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6939009/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com