tags:

views:

43

answers:

1

I feel a little embarassed posting two questions relating to the same problem, but the first one ended up answering a question that I believe is unrelated to the solution so I'm leaving it up and outlining what I'm trying to accomplish with the hopes that someone can help out a .Net noob.

What I need to be able to do is create a field in my gridview that contains a link that passes two variables. One is pulled from within the gridviews datasource and the other needs to be pulled from a textbox control outside the gridview.

From what I've read so far you cannot use a hyperlinkfield for this as the datanavigateurlfields cannot be set to pull from anything but the gridview's data source.

What I attempted to do was create a template field where in the itemtemplate I called:

<a href="example.aspx?e=<%# Eval(ExampleList.SelectedItem.Value) %>">Test</a>

That comes back with an error like this:

DataBinding: 'System.Data.DataRowView' does not contain a property with the value 'TestData'

Any clues to make this happen would be appreciated, like I said I'm pretty new to .Net so please be gentle. I tried to do my homework before posting this.

+2  A: 

How about putting a hyperlink server control in your GridView template column as below.

<asp:Hyperlink id="hyperlink" runat="server" onDataBinding="hyperlink_DataBinding" text="Click ME" />

Then in your code behind add this data binding event for the hyperlink.

protected void hyperlink_DataBinding(object sender, EventArgs e) {
    HyperLink link = (HyperLink) sender;
    string param1 = Eval("field").ToString();
    string param2 = ExampleList.SelectedItem.Value;
    link.NavigateUrl = "example.aspx?e=" + param1 + "&f=" + param2;
}
Germ
I'm assuming the line string param = Eval("<DataSource Expression").ToString(); Is where it pulls in the part from my gridview's datasource that needs to be included as well?I'm just making sure I understand what this is doing so I don't have to ask a thousand dumb questions later on.
Mike Keller
So if your gridview datasource is a DataTable or DataSet, it will be the field name of the column. If it's a custom object it will be the name of the property.
Germ
I think I see your edit there. That makes things clearer for me. I appreciate the help Germ!
Mike Keller
@Mike: feel free to click the Up Arrow to give some reputation to the answerer!
p.campbell
I just got my 15 reputation points to be able to do so thanks to your comment pcampbell. :)
Mike Keller