海族小学生
我正在做一个关于在线教育的项目。在我的项目中,我以网格视图显示中的实习生/培训者。如果我从网格视图中选择任何数据,它必须在下面的标签中显示出来。我该怎么做呢?
提前感谢那些回答的人。
发布于 2009-10-20 05:11:12
使用asp:LinkButton显示每列中的数据。将commandArgument设置为数据。在gridview rowcommand事件中设置相同的comandname并处理rowcommand。
尝试以下操作:
aspx页面中的:
<asp:GridView ID="GridView1" OnRowCommand="GridView1_RowCommand" runat="server">
<Columns>
<asp:TemplateField HeaderText="CategoryID">
<ItemTemplate>
<asp:LinkButton ID="lnkID" runat="server" CommandName="sel" CommandArgument='<%# DataBinder.Eval(Container,"DataItem.CategoryID") %>'
Text='<%# DataBinder.Eval(Container,"DataItem.CategoryID") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CategoryName">
<ItemTemplate>
<asp:LinkButton ID="lnkName" runat="server" CommandName="sel" CommandArgument='<%# DataBinder.Eval(Container,"DataItem.CategoryName") %>'
Text='<%# DataBinder.Eval(Container,"DataItem.CategoryName") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="lblCat" runat="server"></asp:Label>aspx.cs页面中的:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "sel")
{
lblCat.Text = e.CommandArgument;
}
}https://stackoverflow.com/questions/1592525
复制相似问题