Getting information from a control databound to a grid view

25 02 2009

Although this title is somewhat specific, I’m sure this would work in other contexts. This is just the context I found this snippet of code useful in. In my gridview, I had a databound link button where the text was a filename. Upon clicking the button, in the event being fired, I needed to get this filename back from the link button, but as the button is created dynamically, it doesn’t actually exist where the C# code is concerned. So my code went as follows:

protected void linkFileName_OnClick(object sender, EventArgs e)
string path = BLL.TransactionSummary.GetPoolWithDateDir(int.Parse(hdTransID.Value), true) + ((System.Web.UI.WebControls.LinkButton)(sender)).Text;
FileUtility.DownloadFile(this.Page, path);

So in order to get the text back, I had to use the sender object, cast it as a link button, and get the text property.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: