我在页面上的DATAGRID中加了个超链接列
<asp:HyperLinkColumn HeaderText="选择" Text="选择" NavigateUrl="top.aspx?p1=1"></asp:HyperLinkColumn>我现在想把他写到.CS文件中去不想把他放在ASPX页面中要怎么做,有没有好的解答呀.(注明,主要是想把NavigateUrl="top.aspx?p1=1"这句写到代码页中去也就是CS文件中)
<asp:HyperLinkColumn HeaderText="选择" Text="选择" NavigateUrl="top.aspx?p1=1"></asp:HyperLinkColumn>我现在想把他写到.CS文件中去不想把他放在ASPX页面中要怎么做,有没有好的解答呀.(注明,主要是想把NavigateUrl="top.aspx?p1=1"这句写到代码页中去也就是CS文件中)
然后在 item_cammand事件里面写代码
Server.Transfer("top.aspx?top=1");
假设 超链接列 为datagrid1的第一列。HyperLinkColumn h=(HyperLinkColumn)this.datagrid1.Columns[0];
h.NavigateUrl="top.aspx?p1=1";
平时我做都是用模板的,贴段以前的;
.cs里
#region 得到用户名 /// <summary>
/// 得到用户名
/// </summary>
/// <returns></returns>
public string Getusername()
{
string strUsername=userTemp.userName;
return strUsername;
} #endregion
页面:
<asp:TemplateColumn HeaderText="设置">
<ItemTemplate>
<table cellpadding="0" cellspacing="0">
<tr height="10">
<td height="10">
<button style="WIDTH: 70px"class="ButtonCss" onclick='window.open("Order.aspx?strOrderNoid=<%#DataBinder.Eval(Container.DataItem,"派工单号")%>&username=<%=Getusername()%>&pagename=query", "newwindow", "height=320, width=600, toolbar=no, menubar=no, scrollbars=auto, resizable=no, location=no, status=no,left=200,top=200")'>
设置 </button>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
if((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
你的代码
}