如何通过命令按钮发送多个命令参数?(RowCommand 事件)
我正在尝试在调用 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();
}
}
请指出错误。我已经尝试过调试,但无法判断出了什么问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Pavitar,尝试 -
绑定 - 它是双向绑定,用于将修改后的数据传递到服务器端。 ASP 无法将客户端的一个值分离到多个服务器属性。
Pavitar, try -
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.