Question

G

Guest

I have a hyperlink column in the datagrid as follows bound to a column in thr
database. How can i add another query string to it to send Row number of the
datagrid to the target page:

<asp:HyperLinkColumn Target="_parent" DataNavigateUrlField="HREF"
DataNavigateUrlFormatString="detailspage.aspx?id={0}" DataTextField="From"
SortExpression="From" HeaderText="From">
<ItemStyle Width="20%"></ItemStyle>
</asp:HyperLinkColumn>
do somethink like this?


<asp:HyperLinkColumn Target="_parent" DataNavigateUrlField="HREF"
DataNavigateUrlFormatString="detailspage.aspx?id={0}&rownumber"+Datagrid.RowNumber DataTextField="From" SortExpression="From" HeaderText="From">
<ItemStyle Width="20%"></ItemStyle>
</asp:HyperLinkColumn>


Thanks

Manny
 
G

Guest

Manny,

To get this to work you have to switch the hyperlink column to a template
column and use an asp:Hyperlink tag. I have pasted a sample in C# below for
your aid.

I hope this helps.
--------------------------

<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="Example">
<ItemTemplate>
<asp:Hyperlink runat="server"
Text='<%#DataBinder.Eval(Container.DataItem,"LastName")%>'
NavigateUrl='<%# "http://localhost/lastname=" +
DataBinder.Eval(Container.DataItem,"LastName") +
"&rownumber=" +
DataBinder.Eval(Container.DataItem,"EmployeeID")%>' />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
 
E

Elton Wang

Hi Manny,

Another way to do it is coding in datagrid_ItemDataBound.
Suppose the HyperLinkColumn is the first column, following
code snippet shows how to create URL for the
HyperLinkColumn.

DataRowView drv = (DataRowView)e.Item.DataItem;
TableCell linkCell = (TableCell)e.Item.Controls[0];
HyperLink link = (HyperLink)linkCell.Controls[0];
link.NavigateUrl = "detailspage.aspx?ID=" + drv
["ID"].ToString() + "&rownumnber=" + e.Item.ItemIndex;


Hope it's helpful to you.

Elton Wang
(e-mail address removed)
-----Original Message-----
I have a hyperlink column in the datagrid as follows bound to a column in thr
database. How can i add another query string to it to send Row number of the
datagrid to the target page:

<asp:HyperLinkColumn Target="_parent" DataNavigateUrlField="HREF"
DataTextField="From"
SortExpression="From" HeaderText="From">
<ItemStyle Width="20%"></ItemStyle>
</asp:HyperLinkColumn>
do somethink like this?


<asp:HyperLinkColumn Target="_parent" DataNavigateUrlField="HREF"
DataNavigateUrlFormatString="detailspage.aspx?id={0}
&rownumber"+Datagrid.RowNumber DataTextField="From"
SortExpression="From" HeaderText="From">
 
G

Guest

Thanks a lot. This really helps

Elton Wang said:
Hi Manny,

Another way to do it is coding in datagrid_ItemDataBound.
Suppose the HyperLinkColumn is the first column, following
code snippet shows how to create URL for the
HyperLinkColumn.

DataRowView drv = (DataRowView)e.Item.DataItem;
TableCell linkCell = (TableCell)e.Item.Controls[0];
HyperLink link = (HyperLink)linkCell.Controls[0];
link.NavigateUrl = "detailspage.aspx?ID=" + drv
["ID"].ToString() + "&rownumnber=" + e.Item.ItemIndex;


Hope it's helpful to you.

Elton Wang
(e-mail address removed)
-----Original Message-----
I have a hyperlink column in the datagrid as follows bound to a column in thr
database. How can i add another query string to it to send Row number of the
datagrid to the target page:

<asp:HyperLinkColumn Target="_parent" DataNavigateUrlField="HREF"
DataTextField="From"
SortExpression="From" HeaderText="From">
<ItemStyle Width="20%"></ItemStyle>
</asp:HyperLinkColumn>
do somethink like this?


<asp:HyperLinkColumn Target="_parent" DataNavigateUrlField="HREF"
DataNavigateUrlFormatString="detailspage.aspx?id={0}
&rownumber"+Datagrid.RowNumber DataTextField="From"
SortExpression="From" HeaderText="From">
<ItemStyle Width="20%"></ItemStyle>
</asp:HyperLinkColumn>


Thanks

Manny
.
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top