How to pass QueryString values in Asp:HyperlinkColumn
-
Hi, How can I pass two querystring variables in asp:HyperlinkColumn... This is the one I am passing, I need to pass another variable too.... Is it possible to pass multiple querystring values... thanks
-
Hi, How can I pass two querystring variables in asp:HyperlinkColumn... This is the one I am passing, I need to pass another variable too.... Is it possible to pass multiple querystring values... thanks
Disclaimer, Im only a newbie, and there is probably a better way..with that said I do something similar, but I handle it through the ItemDataBound Event. However when I first Bind my datagrid to my dataset, I create a new column for Href and for each record in the in the result set, I create the associated query string with the proper ID's. The below line is located in my BindGrid Function
For Each categoryRow In DepartmentRow.GetChildRows(dr) aNewRow = Ds.Tables("Menu").NewRow aNewRow.Item(0) = DepartmentRow.Item(0) aNewRow.Item(1) = categoryRow.Item(1) aNewRow.Item(2) = "?DID=" & DepartmentRow.Item(0).ToString & "&CID=" & categoryRow.Item(1).ToString aNewRow.Item(3) = " " & categoryRow.Item(2).ToString 'Add the cat row to the main datatable Ds.Tables("Menu").Rows.Add(aNewRow) Next categoryRow DataGrid1.DataSource = Ds.Tables(0).DefaultView DataGrid1.DataBind() DataGrid1.Columns(0).Visible = True DataGrid1.Columns(1).Visible = False DataGrid1.Columns(2).Visible = False DataGrid1.Columns(3).Visible = True
This Href column is a hidden column in my datagrid, then in the ItemDataBound event,I can access this QueryString for each record like this and assign it to the LinkButton's NavigateUrl Property:Protected Sub DataGrid1_ItemBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then Dim qryString As String = CType(e.Item.DataItem, DataRowView)(2).ToString CType(e.Item.FindControl("linkname"), HyperLink).NavigateUrl = PathPrefix() & qryString CType(e.Item.FindControl("mnuCell"), HtmlTableCell).Attributes.Add("onClick", "document.location.href='" & PathPrefix() & qryString & "'") End If End Sub
Remember the Column indexed 2 (the third colum) in my datagrid is hidden, but this way I have it there on the first binding, and on all postbacks. Hope this helps -
Hi, How can I pass two querystring variables in asp:HyperlinkColumn... This is the one I am passing, I need to pass another variable too.... Is it possible to pass multiple querystring values... thanks
Hi there, With the HyperLinkColumn, you can only specify a single data field for the column, so you cannot pass multiple parameters to the query string. Using the code-behind suggested by Shawn is an option, and there is a simple way is to use a template column with a hyperlink control:
asp:TemplateColumn
<ItemTemplate>
<asp:HyperLink runat="server" Text="MileStoneId"
NavigateUrl='<%# "CreateMileStone.aspx?MileStoneId=" +
Container.DataItem("MileStoneId") +
"&MileStoneText=" + Container.DataItem("MileStoneText") %>' />
</ItemTemplate>
</asp:TemplateColumn> -
Hi there, With the HyperLinkColumn, you can only specify a single data field for the column, so you cannot pass multiple parameters to the query string. Using the code-behind suggested by Shawn is an option, and there is a simple way is to use a template column with a hyperlink control:
asp:TemplateColumn
<ItemTemplate>
<asp:HyperLink runat="server" Text="MileStoneId"
NavigateUrl='<%# "CreateMileStone.aspx?MileStoneId=" +
Container.DataItem("MileStoneId") +
"&MileStoneText=" + Container.DataItem("MileStoneText") %>' />
</ItemTemplate>
</asp:TemplateColumn> -
Ahhh Yes minhpc, I knew if I stuck my neck out there you would reveal a better way....thanks! Shawn
Wow, Shawn! You might have no idea that I was just about to post a reply to your post to let you know that you can use the databinding expressions to populate the NavigateUrl property. :). In fact, creating an additional field which is the result of combining other fields is also an option.
-
Wow, Shawn! You might have no idea that I was just about to post a reply to your post to let you know that you can use the databinding expressions to populate the NavigateUrl property. :). In fact, creating an additional field which is the result of combining other fields is also an option.
So you mean creating an additional field in the original dataset like I did in my example, but then Binding it in the aspx page like you showed in your example, but just binding to the one field (The one you create by making the whole query string)? I hope that made sense Shawn
-
So you mean creating an additional field in the original dataset like I did in my example, but then Binding it in the aspx page like you showed in your example, but just binding to the one field (The one you create by making the whole query string)? I hope that made sense Shawn
Yes, if you create an additional field in the dataset, you just bind the control to this single field. If you don't like creating a new field, then you can use databind epxressions for multiple fields, and finally concatenate them. You can take a look at this document: Data Binding Expression Syntax[^]
-
Yes, if you create an additional field in the dataset, you just bind the control to this single field. If you don't like creating a new field, then you can use databind epxressions for multiple fields, and finally concatenate them. You can take a look at this document: Data Binding Expression Syntax[^]
Thanks a lot :)