我将在pmuserlist.aspx中传递所选的用户id,并将其传递给useredit.aspx。网格视图表数据来自mysql。例如,我想编辑id为“15001”的用户。然后我按了同一行的“编辑”按钮。我希望将“15001”传递到useredit.aspx
结果1
预期结果:预期结果
数据库结构:用户id是一个字符串。
pmuserlist.aspx文件
<asp:GridView ID="gvUserList" runat="server" AllowPaging="True" PageSize="5" SelectedIndex="0" >
<Columns>
<asp:BoundField DataField="user_id" HeaderText="User ID" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="contact_no" HeaderText="Contact no" SortExpression="Contact" />
<asp:BoundField DataField="email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="role" HeaderText="Role" SortExpression="Role" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="BtnEdit"
runat="server"
Text="Edit"
ForeColor="Black"
CommandArgument='<%# Eval("user_id") %>'
OnCommand="BtnEdit_Command"
OnClientClick='<%# "javascript:return confirm(\"Edit [" + Eval("user_id") + "]\");" %>' />
</ItemTemplate>
pmuserlist.aspx.cs
protected void BtnEdit_Command(object sender, CommandEventArgs e)
{
Session["userid"] = String.Format("PMUserList?user_id={0}", e.CommandArgument);
string url = String.Format("PMUserList?user_id={0}", e.CommandArgument);
Response.Redirect("UserEdit.aspx");
}
用户编辑.aspx.cs
private void LoadData()
{
string userid = Session["userid"].ToString();*/
string Query = "SELECT user_id, name, contact_no,email,role FROM mydb.User WHERE user_id = " + userid + ";";
.....}
错误消息(可选择“15001”,但传递“?15001”):
{"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?user_id=15001' at line 1"}
请帮助我改进会话变量。谢谢您。
1条答案
按热度按时间lskq00tm1#
会话变量存储的是查询字符串,而不仅仅是我指定的用户,因此sql查询无效。只需在btn\u命令中存储userid,或者只从load data中的session变量中获取用户id并进行sql查询