GridView最后一列是模板列,放置了一个linkbutton,主要功能是点击后查看该列内容的详情。所以要给linkbutton加上一个页面链接,后面带上该行的datakey做参数。不知道该如何实现了。前面还有两个linkbutton分别做更新和删除的,可以用update和delete这样的command命令,获得this.GridView1.DataKeys[e.RowIndex].Value,然后就能定位到相应的数据了。不知道除了这两个还有什么办法能获得datakey??
调试欢乐多
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbtn_1" CommandArgument='<%#Eval("key") %>' runat="server" CommandName="comand"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "comand")
{
Response.Write(e.CommandArgument.ToString());
}
}
{
LinkButton LBN=(LinkButton)e.Row.FindControl("LinkButton1");
if(LBN != null)
{
LBN.Attributes.Add("onclick","window.open('NextPage.aspx?id="+e.Row.Cells[0].Text.toString()+"')");
}
}
其中NextPage.aspx是详细信息页面,Cells[0]中的0是主键列的索引,看第几列就把0 换成几
还是这个
<%#DataBinder.Eval(Container.DataItem,"字段名")%>