开发者

Including Data From DropDownList Into Gridview

开发者 https://www.devze.com 2022-12-27 16:33 出处:网络
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 out

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开发者_StackOverflow中文版 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.


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消