本文介绍了asp.net gridviw控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好专家,
我的应用程序我动态绑定了一个gridview。
i希望如果用户点击任何一行标签值将随所选行的第一列而改变。
帮帮我!
hello experts,
in my application i am binding a gridview dynamically.
i want that if usedr click on any row a label value will be change with first column of that selected row.
help me!
推荐答案
<asp:GridView ID="GridView1" runat="server" CellPadding="4" GridLines="None"
BorderColor="#FB7F05" BorderStyle="Solid" BorderWidth="1px"
CellSpacing="2" AutoGenerateColumns="false" Width="100%"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Start/Stop">
<ItemTemplate>
<asp:Button ID="ChangeStatus" runat="server" Text="" CommandName="Status" CommandArgument='<%# Eval("StatusName") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代码背后
--------------------
code behind
--------------------
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow) (((Button)e.CommandSource).NamingContainer);
Label MYLabel = (Label)row.FindControl("Label1");
MYLabel.Text = "MyText";
}
这篇关于asp.net gridviw控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!