Help on DataBinding ??

G

Guest

Dear all,

I have a datagrid which is populated with a dataset as follow:

myDataGrid.DataSource = ds.Tables(0)
myDataGrid.DataBind()

Then I need to create a Hyperlink column from my grid.Clicking on that lik
will pass the content of the click link to a page. For that I add the
following to my page :

<asp:HyperLinkColumn>
DataNavigateUrlField='<% "Event.aspx?ReelId=" & Container.DataItem("ID")
%>' </asp:HyperLinkColumn>

When running my application, I get an error message saying that the field ID
is not existing in the grid datasource.

Then I check the content of my dataset which is pass to the grid as
datasource by watching the content of ds.Tables(0).Columns(0) and the name
of that first column I am interresting in is "ID".

How do you explain that it cannot bind to the column in my dataset ?
What did I do wrong ??

Thnaks for your help

regards
serge
 
P

Patrick.O.Ige

Try
<asp:HyperLinkColumn Text="Hyperlink Text"
DataNavigateUrlField="SomeDataSourceField"
DataNavigateUrlFormatString="mysample.aspx?ID={0}"
Target="_blank" />

Hope that helps
Patrick
 
G

Guest

Hi patrick

Thanks for your answer.
I have test that and I am quite surprise that the principle works fine..



But things needs to be clarify:

First of all doing like this adds an extra column in my datagrid with the
same content and the column which is in my dataset bound to the grid.
In other words I have 2 similar columns.

Is it possible to do that based on my already bound columns instead of
adding a new one ?

The second point is to know if there is a possiblity to catch the click
event on the link before it is postback to the server. This in a similar way
has the "CommandName" tag of the ButtonColumn ?

And as the last question, any idea why the previous solution was not working ?
 
R

Rote Rote

Yes Serge the ne you posted earlier wasn't working becos you weren't
giving the right values to the HyperlinkColumn
And yes you can keep adding if you need to have more HyperLinkColumns..

If you need more flexibility try using TemplateColumns and in there add
controls you need
Hope that helps
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top