Hi
How to set hyperlink in webdatagrid and once user click on any link i need to pass some data in querystring to another page ,
One more question is how to get selected row changed severside event for WebDataGrid
Easiest way is to use TemplatedColumn and put HyperLink in a template. There you should be able to use binding expressions (<%# Eval("SomeProperty") %>), but you can't mix regular text and expressions so you have two options:
1) Handle WebDataGrid's InitializeRow event and there you can set hyperlink's url2) Create a separate method for constructing. Then use it in your binding expressions (<%# GenerateUrl(Eval("SomeProperty")) %> for example). Of course, you should take care of casting where necessary.
Would you give me any example ?
When using InitializeRow approach then code would be similiar to:
protected void WebDataGrid_InitializeRow(object sender, RowEventArgs args) { var dataItem = (PartnerDataContract)args.Row.DataItem; var grid = (WebDataGrid)args.Row.Items.Grid; var hyeprLink = (HyperLink)args.Row.Items[grid.Columns["HyperLinkColumn"].Index].FindControl("HyperLinkId"); hyeprLink.NavigateUrl = "Default.aspx?param=" + dataItem.Name; }
There may be some problems when using FindControl directly, not sure how IG handles templates and containers.
When using other approach, then this should work:
public string CreateUrl(PartnerDataContract partner) { return "Default.aspx?param=" + partner.Name; }
And in the template you could define: <asp:HyperLink runat="server" ID="HyperLInk" NavigateUrl='<%# CreateUrl((Partner)((TemplateContainer)Container).DataItem) %>' Text='<%# Eval("SomeTextProperty") %>' />
Hope it helps.
Hi Thanks for help
But i using vb and still not get it what's that PartnerDataContaract
Please give me code in VB if you have
Sorry, I took it form my own project.
I'm using objectdatasource as the data source of the webdatagrid and so it's just a type of the object i'm using.
And I can't help you with the VB code, because I've never wrote any...