我想为 Gridview 设置 CommandArgument,但是如果我运行程序,则会发生错误。
这是我的 ButtonField 声明:
<asp:ButtonField Text="Löschen" CommandName="Deleterecord" ButtonType="Button" CommandArgument=<% Eval("userId") %> />
这是错误:
Parser Error Message: Literal content ('<asp:ButtonField Text="Löschen" CommandName="Deleterecord" ButtonType="Button" CommandArgument=') is not allowed within a 'System.Web.UI.WebControls.DataControlFieldCollection'.
编辑:
使用这些代码块,我填充了我的 Gridview:
protected void Button2_Click(object sender, EventArgs e)
{
Guid g = Guid.Parse("ef7a9f97-6a9a-44c6-ac38-82a5d06c394e");
RoutesManager rm = new RoutesManager(g);
rm.GetAllRoutes();
List<Route> result;
result=rm.GetAllRoutes();
GridView1.DataSource = result;
GridView1.DataBind();
}
这是GetallRoutes:
public List<Route> GetAllRoutes()
{
var inputParams = new Dictionary<string, object>();
var xmlHelper = new XmlHelper();
var result = new List<Route>();
inputParams.Add("UserId", _userId);
DataTable dt = _dbhelper.Select("SELECT * FROM ROUTES WHERE UserId=@UserId", inputParams);
foreach (DataRow row in dt.Rows)
{
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(row[XmldocPosition].ToString());
result.Add(xmlHelper.ConvertXmlDocumentToRoute(xmlDoc.ToXDocument()));
}
return result;
}
我的网格视图充满了这段代码,我在我的 Gridview 中为每一行放置了一个链接按钮,如果用户单击此按钮,我希望仅从 DB 和 Gridview 中删除该行