gridview模板中有button和label 开始时隐藏lable显示button 点击button后隐藏button并显示lable
2个回答
展开全部
一、 加入事件GridView RowCommand
二、给btn加属性 CommandArgument,CommandName
<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText=" 确认付款">
<ItemTemplate>
<asp:Label ID="LabIsPay" runat="server" Text="已付款" Visible="false"></asp:Label>
<asp:Button ID="ButIsPay" runat="server" Text="确认付款" CommandArgument='<%# Container.DataItemIndex %>' CommandName="showAndHide" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName=="showAndHide")
{
Label lbl = GridView1.Rows[index].FindControl("LabIsPay") as Label;
Button btn = GridView1.Rows[index].FindControl("ButIsPay") as Button;
lbl.Visible = true;
btn.Visible = false;
}
}
二、给btn加属性 CommandArgument,CommandName
<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText=" 确认付款">
<ItemTemplate>
<asp:Label ID="LabIsPay" runat="server" Text="已付款" Visible="false"></asp:Label>
<asp:Button ID="ButIsPay" runat="server" Text="确认付款" CommandArgument='<%# Container.DataItemIndex %>' CommandName="showAndHide" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName=="showAndHide")
{
Label lbl = GridView1.Rows[index].FindControl("LabIsPay") as Label;
Button btn = GridView1.Rows[index].FindControl("ButIsPay") as Button;
lbl.Visible = true;
btn.Visible = false;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询