Reputation: 89
I have a button like this in my gridview,
<asp:LinkButton runat="server" ID="lnkCustDetails" Text='<%# Eval("CustomerID") %>' OnClick="lnkCustDetails_Click" />
and I get the id like this:
protected void lnkCustDetails_Click(object sender, EventArgs e)
{
LinkButton lb = sender as LinkButton;
string custID = lb.Text;
lblCustValue.Text = custID;
ModalPopupExtender1.Show();
}
My problem is, what can I use instead of having the id in Text='<%# Eval("CustomerID") %>'
because this displays the id of the customer in the linbutton, when I want the link button to display "Details"
Upvotes: 2
Views: 3331
Reputation: 56716
You can switch to handling commands instead of clicks:
<asp:LinkButton runat="server" ID="lnkCustDetails"
Text='Details'
CommandArgument='<%# Eval("CustomerID") %>'
OnCommand="lnkCustDetails_Click" />
And to get the id:
protected void lnkCustDetails_Click(object sender, EventArgs e)
{
LinkButton lb = sender as LinkButton;
string custID = lb.CommandArgument;
lblCustValue.Text = custID;
ModalPopupExtender1.Show();
}
One note though: I am not sure if you can handle LinkButton's command directly if it lives inside the grid view. You might need to subscribe to grid view's On Command instead - please check.
Upvotes: 1