如何在OnClick事件上更改gridview templatefield的可见性

时间:2011-07-31 07:03:06

标签: c# asp.net gridview

如何在OnClick事件上更改gridview模板字段的可见性。

 <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:TemplateField>
</Columns>
</grdFranchies>

我希望当gridview加载时,lblNetPayments只能看到true。当用户单击批量分配时,lblNetPayments标签可见性为false或checkMyPaymentStatus visiblility为true且txtMyPayment可见性为真。

当用户点击批量提交时,上面的内容相反。

1 个答案:

答案 0 :(得分:1)

隐藏lblNetPaymentstxtMyPayment并在checkMyPaymentStatus事件上显示btnBulkAssign_Click

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;
  }
}

要反向调用grdFranchise.DataBind();上的btnBulkSubmit_Click