设置Gridview的CommandArgument [英] Setting CommandArgument for a Gridview
问题描述
我想为Gridview设置CommandArgument,但是如果运行程序,则会发生错误.
I want to set a CommandArgument for a Gridview but if I run the programm an error occured.
这是我的ButtonField声明:
Here is my ButtonField declaration:
<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:
with these block of code I fill my 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:
and this is 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中删除该行
My grid view full with this block of code ,I put a link button in my Gridview for each Row and I want if the user click this button only this row is deleted from DB and Gridview
推荐答案
您丢失了
- 右括号
-
userID
上的双引号 -
单引号包含CommandArgument的结果值
- A closing bracket
- Double quotes on the
userID
Single quote to contain the resulting value of CommandArgument
< asp:ButtonField Text =Löschen" CommandName ="Deleterecord" ButtonType ="Button" CommandArgument ='<%#Eval("userId")%>'/>
这篇关于设置Gridview的CommandArgument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!