Reputation: 1272
I have got this in my ItemTemplate of the listView:
<ItemTemplate>
<tr style="background-color: #FFFBD6;color: #333333;">
<td>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Select" >'<%# Eval("MessageTitle") %>'</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
I want on the linkbuttons click to get the "MessageID"..which is my datakeyname..
So far I did this:
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
string recordID = (e.Item.DataItemIndex).ToString(); //I get 0 all the time as my recordID
Server.Transfer("~/Moderator/ObserveMessage.aspx?MessageID=" + recordID);
}
But it doesnt work;;
Upvotes: 0
Views: 298
Reputation: 52241
e.CommandArgument
Will give you the DataKeyValue for the selected Row. e.g.
You need to add CommandArgument='<%# Eval("MessageID") %>'
to your linkbutton
<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("MessageID") %>' runat="server" CommandName="Select" >'<%# Eval("MessageTitle") %>'</asp:LinkButton>
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
string recordID = e.CommandArgument;
Server.Transfer("~/Moderator/ObserveMessage.aspx?MessageID=" + recordID);
}
Upvotes: 1