What I want to do is a button that edits me by SQL , and I have that, but I need the ID of the row to edit (I extract it from with Eval("id")
of listview1
).
I have a ListView
that within ItemTemplate
there is a button ( btnSeguir
) with property commandName = "seguir"
.
listview
:
<asp:ListView
ID="ListView1"
runat="server"
OnItemCommand="ListView1_ItemCommand"
DataSourceID="SqlDataSource1"
>
Button in ItemTemplate
of listview1
:
<asp:LinkButton
ID="btnSeguir"
CommandName="seguir"
runat="server"
><%# siguiendo() %></asp:LinkButton>
In the ListView1_ItemCommand
I want to call the function Eval("id")
of ListView1
:
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "seguir")
{
ConsultasSQL c = new ConsultasSQL("XConnectionString");
c.seguir(Eval("id")+"", Session["usrid"].ToString());
ListView1.DataBind();
}
}
But when I run it, when I hit the btnFollow button, I get this error:
System.InvalidOperationException: 'Data link methods such as Eval (), XPath () and Bind () can only be used in the context of a data link control.'
The strange thing is that I work with the siguiendo()
method of the button, which also calls Eval("id")
and if I extract the data, but in itemCommand
no.
How do I solve this? Is there any other way to do this?