第一种:后台再绑定:
private void mygrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[0].Controls[0];
string url = link.NavigateUrl;
url += "?id=" + e.Item.Cells[1].Text + "&id2=" + e.Item.Cells[2].Text;
link.NavigateUrl = url;
}
}
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HyperLink link = (HyperLink)e.Item.Cells[0].Controls[0];
string url = link.NavigateUrl;
url += "?id=" + e.Item.Cells[1].Text + "&id2=" + e.Item.Cells[2].Text;
link.NavigateUrl = url;
}
}
第二种:前台增加模板列:
<asp:TemplateColumn HeaderText="test">
<ItemTemplate>
<asp:HyperLink runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.productID") %>' NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.productName", "detailspage.aspx?id={0}&id2="+DataBinder.Eval(Container, "DataItem.productID")) %>'>
</asp:HyperLink>
</ItemTemplate>
<ItemTemplate>
<asp:HyperLink runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.productID") %>' NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.productName", "detailspage.aspx?id={0}&id2="+DataBinder.Eval(Container, "DataItem.productID")) %>'>
</asp:HyperLink>
</ItemTemplate>
或
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#String.Format("show.aspx?str={0}&mat={1}",DataBinder.Eval(Container.DataItem,"supplier_id"),DataBinder.Eval(Container.DataItem,"material_po")) %>'>打开</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#String.Format("show.aspx?str={0}&mat={1}",DataBinder.Eval(Container.DataItem,"supplier_id"),DataBinder.Eval(Container.DataItem,"material_po")) %>'>打开</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
转自:http://blog.csdn.net/downmoon/archive/2005/07/11/420941.aspx