How change visibility of gridview template field on OnClick event.
<gaia:Button ID="btnAdd" runat="server" Text="Add Sub Franchise" OnClick="btnAdd_Click" Visible="true" CssClass="b2" />
<gaia:Button ID="btnBulk" runat="server" Text="Bulk Assignment"
CssClass="b2" onclick="btnBulkAssign_Click" />
<gaia:Button ID="btnBulkSubmit" Visible="false" runat="server"
Text="Bulk Submit" CssClass="b2" onclick="btnBulkSubmit_Click" />
<asp:GridView ID="grdFranchise" runat="server" AllowSorting="True" AutoGenerateColumns="False"
>
<Columns>
<asp:TemplateField HeaderText="Payments">
<ItemTemplate>
<asp:Label runat="server" ID="checkMyPaymentStatus" Visible="<%# Paymentflag %>" Text='<%#GetTotal("lblDeposit")%>' ForeColor='Green' />
<asp:Label runat="server" ID="lblNetPayments" Text='<%#String.Format("{0:f2}",(decimal)Eval("Payments"))%>'/>
<asp:TextBox ID="txtMypayment" runat="server" Visible="<%# Paymentflag %>" Text='<%#String.Format("{0:f2}",(decimal)Eval("Payments"))%>'/> </ItemTemplate> </asp:Templa开发者_StackOverflowteField>
</Columns>
</grdFranchies>
I want when gridview is load then lblNetPayments is visible true only. and when user click Bulk Assignment then lblNetPayments label visibility is false or checkMyPaymentStatus visiblility is true and txtMyPayment visibility is true.
AND when user click on Bulk submit then above is reverse.
To do hide lblNetPayments
and txtMyPayment
and show checkMyPaymentStatus
on btnBulkAssign_Click
event:
protected void btnBulkAssign_Click(object sender, EventArgs e)
{
for (int i = 0, i < grdFranchise.Rows.Count, i++)
{
Label lblNetPayments = (Label)grdFranchise.Rows[i].FindControl("lblNetPayments");
Label checkMyPaymentStatus = (Label)grdFranchise.Rows[i].FindControl("checkMyPaymentStatus ");
TextBox txtMypayment = (TextBox)grdFranchise.Rows[i].FindControl("txtMypayment");
lblNetPayments.Visible = false;
checkMyPaymentStatus.Visible = true;
txtMypayment.Visible = true;
}
}
To reverse just call grdFranchise.DataBind();
on btnBulkSubmit_Click
.
精彩评论