Every row in my gridview is supposed to have a button/hyperlink that navigates to Page?id=something
Then there’s javascript that catches the redirect and prints the page as an iframe.
This something is and already available in the row (but hidden).
So i’d want to do something like NavigateUrl = “~/Page.aspx?id=” + Id.ToString() for each field, but the thing is the Id is populated in DataBind() from a LINQ datasource.
<asp:GridView ID="gridleitNidurstada" runat="server" GridLines="None" AllowPaging="True"
CssClass="mGrid" PagerStyle-CssClass="pgr" DataKeyNames="Id" OnRowDataBound="gridLeit_RowDataBound"
AllowSorting="True" SortedAscendingHeaderStyle-CssClass="sortasc-header" SortedDescendingHeaderStyle-CssClass="sortdesc-header"
OnSorting="gridleitNidurstada_Sorting" CurrentSortField="Id" CurrentSortDir="Ascending"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" Visible="false"/>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField HeaderText="Print" Text="Print" **anything here?**/>
</Columns>
<PagerStyle CssClass="pgr"></PagerStyle>
<SortedAscendingHeaderStyle CssClass="sortasc-header"></SortedAscendingHeaderStyle>
<SortedDescendingHeaderStyle CssClass="sortdesc-header"></SortedDescendingHeaderStyle>
</asp:GridView>
Binding is something like this: Could i do it there?
Or in the rowbound event?
IQueryable<model.SomeClass> someClass =
from m in preparePredicate()
select new model.SomeClass
{
Id = m.id,
...
};
gridleitNidurstada.DataSource = someClass;
gridleitNidurstada.DataBind();
You can use the following syntax:
More information here and here on MSDN.
EDIT:
If you don’t know the exact url when creating the grid, you’ll have to do a bit more work.
An example I’ve worked on this week, using an itemtemplate. But in order to use this, you have to set
EnableSortingAndPagingCallbackstofalse. And do some extra work in code behind for this.I’ve only used paging on my grid, so this sample I can provide.
Markup:
Code behind: