在DataGrid中我有一个超链接列,运行时,当我点击该列中的一个链接时,会从当前页面(title.aspx)跳到另一个页面(particular.aspx),并且通过地址栏来传递数据库中的两列的值(一个是ID列的值,一个是parent_id列的值)到particular.aspx页。昨天一位大哥教我一种方法,但是不能做的,当加载title.aspx时就出错了,出错信息:未将对象引用设置到对象的实例。 行 242:link.Attributes.Add("onclick","window.location.href='particular.aspx?id="+row["id"].ToString()+"&parent="+row["parent_id"].ToString()+"';return false;");
那个大哥,给我的代码是:
<asp:HyperLinkColumn Target="_blank" DataTextField="forum" HeaderText="论坛" NavigateUrl="#"></asp:HyperLinkColumn>
******************************************
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if(e.Item.ItemIndex>-1)
            {
                DataRowView row = e.Item.DataItem as DataRowView;
                System.Web.UI.WebControls.HyperLink link = e.Item.Cells[0].Controls[0] as HyperLink;
                
                link.Attributes.Add("onclick","window.location.href='webform1.aspx?id="+row["id"].ToString()+"&txt=="+row["parent_id"].ToString()+"';return false;");
            }
        }我查了一下DatGeid的ItemDataBound事件是在“项被数据邦定后激发”,是不是这个错了?
大家帮帮忙吧!要是这个方法不行的话,还请大家告诉别的方法?