【发布时间】:2019-03-15 01:56:42
【问题描述】:
下面是我的网格视图
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableModelValidation="True" onrowdatabound="GridView1_RowDataBound" onrowcommand="GridView1_RowCommand" onrowdeleting="GridView1_RowDeleting">
<asp:TemplateField HeaderText="Amount" HeaderStyle-ForeColor="DimGray" >
<ItemTemplate>
<asp:Label ID="lblamount" runat="server" Text='Label' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price" HeaderStyle-ForeColor="DimGray" >
<ItemTemplate>
<asp:Label ID="lblprice" runat="server" Text='Label' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
在 RowData_BoundEvent 中
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl2 = (Label)e.Row.FindControl("lblamount");
if(amount>0) {lbl2.Text = amount;} else lbl2.Text = string.Empty;
Label lbl3 = (Label)e.Row.FindControl("lblprice");
if(price>0) {lbl3.Text = price;} else lbl3.Text = string.Empty;
如果在 Amount 或 Price 中没有输入值,如果金额不大于零,我会尽量不在 gridview 中显示值。但是,如果条件不满足,网格仍将金额显示为标签,价格显示为标签。
【问题讨论】:
标签: asp.net