I want to set a CommandArgument for a Gridview but if I run the programm an error occured.
Here is my ButtonField declaration:
<asp:ButtonField Text="Löschen" CommandName="Deleterecord" ButtonType="Button" CommandArgument=<% Eval("userId") %> />
and this is the error:
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'.
EDIT:
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();
}
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;
}
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
Best Answer
You are missing
userID
Single quote to contain the resulting value of CommandArgument
<asp:ButtonField Text="Löschen" CommandName="Deleterecord" ButtonType="Button" CommandArgument='<%# Eval("userId") %>' />